Merge branch 'masterupstream' into beforeAfterAnnotationsJunit
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.exception;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ExceptionAssertionTest {
|
||||
@Test
|
||||
public void whenExceptionThrown_thenAssertionSucceeds() {
|
||||
String test = null;
|
||||
assertThrows(NullPointerException.class, () -> {
|
||||
test.length();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDerivedExceptionThrown_thenAssertionSucceds() {
|
||||
String test = null;
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
test.length();
|
||||
});
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.migration.junit4;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class ExceptionAssertionTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exceptionRule = ExpectedException.none();
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void whenExceptionThrown_thenExpectationSatisfied() {
|
||||
String test = null;
|
||||
test.length();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenExceptionThrown_thenRuleIsApplied() {
|
||||
exceptionRule.expect(NumberFormatException.class);
|
||||
exceptionRule.expectMessage("For input string");
|
||||
Integer.parseInt("1a");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -54,11 +54,11 @@ public class HamcrestFileUnitTest {
|
||||
assertThat(file, aFileWithSize(greaterThan(1L)));;
|
||||
}
|
||||
|
||||
@Test
|
||||
/*@Test
|
||||
public final void whenVerifyingFilePath_thenCorrect() {
|
||||
File file = new File("src/test/resources/test1.in");
|
||||
|
||||
assertThat(file, aFileWithCanonicalPath(containsString("src/test/resources")));
|
||||
assertThat(file, aFileWithAbsolutePath(containsString("src/test/resources")));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class AssertJConditionUnitTest {
|
||||
assertThat(member).has(nameJohn);
|
||||
fail();
|
||||
} catch (AssertionError e) {
|
||||
assertThat(e).hasMessageContaining("to have:\n <name John>");
|
||||
assertThat(e).hasMessageContaining("<name John>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user