- Added code for JUnit 5 article
This commit is contained in:
parent
c574b94ea3
commit
a875e25b18
|
@ -2,6 +2,7 @@ package com.baeldung;
|
|||
|
||||
import org.junit.gen5.api.Test;
|
||||
|
||||
import static org.junit.gen5.api.Assertions.assertEquals;
|
||||
import static org.junit.gen5.api.Assumptions.assumeFalse;
|
||||
import static org.junit.gen5.api.Assumptions.assumeTrue;
|
||||
import static org.junit.gen5.api.Assumptions.assumingThat;
|
||||
|
@ -11,13 +12,13 @@ public class AssumptionTest {
|
|||
@Test
|
||||
void trueAssumption() {
|
||||
assumeTrue(5 > 1);
|
||||
System.out.println("Was true");
|
||||
assertEquals(5 + 2, 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void falseAssumption() {
|
||||
assumeFalse(5 < 1);
|
||||
System.out.println("Was false");
|
||||
assertEquals(5 + 2, 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -25,7 +26,7 @@ public class AssumptionTest {
|
|||
String someString = "Just a string";
|
||||
assumingThat(
|
||||
someString.equals("Just a string"),
|
||||
() -> System.out.println("Assumption was correct")
|
||||
() -> assertEquals(2 + 2, 4)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.baeldung;
|
|||
|
||||
import org.junit.gen5.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.gen5.api.Assertions.assertEquals;
|
||||
import static org.junit.gen5.api.Assertions.expectThrows;
|
||||
|
||||
|
@ -9,7 +11,8 @@ public class ExceptionTest {
|
|||
|
||||
@Test
|
||||
void shouldThrowException() {
|
||||
Throwable exception = expectThrows(NullPointerException.class, null);
|
||||
ArrayList list = null;
|
||||
Throwable exception = expectThrows(NullPointerException.class, list::clear);
|
||||
assertEquals(exception.getClass(), NullPointerException.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.junit.gen5.api.Disabled;
|
||||
import org.junit.gen5.api.Test;
|
||||
|
||||
import static org.junit.gen5.api.Assertions.assertAll;
|
||||
|
@ -11,7 +12,7 @@ class FirstTest {
|
|||
@Test
|
||||
void lambdaExpressions() {
|
||||
String string = "";
|
||||
assertTrue(() -> string.isEmpty(), "String should be empty");
|
||||
assertTrue(string::isEmpty, "String should be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -24,4 +25,9 @@ class FirstTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void disabledTest() {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.junit.gen5.api.Tag;
|
||||
import org.junit.gen5.api.Test;
|
||||
|
||||
import static org.junit.gen5.api.Assertions.assertEquals;
|
||||
|
||||
@Tag("Test case")
|
||||
public class TaggedTest {
|
||||
|
||||
@Test
|
||||
@Tag("Method")
|
||||
void testMethod() {
|
||||
assertEquals(2+2, 4);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue