diff --git a/junit5/src/test/java/com/baeldung/AssumptionTest.java b/junit5/src/test/java/com/baeldung/AssumptionTest.java index 6e6e56fe0a..634ec9b21e 100644 --- a/junit5/src/test/java/com/baeldung/AssumptionTest.java +++ b/junit5/src/test/java/com/baeldung/AssumptionTest.java @@ -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) ); } } diff --git a/junit5/src/test/java/com/baeldung/ExceptionTest.java b/junit5/src/test/java/com/baeldung/ExceptionTest.java index a9a5b8301d..26c44e8b10 100644 --- a/junit5/src/test/java/com/baeldung/ExceptionTest.java +++ b/junit5/src/test/java/com/baeldung/ExceptionTest.java @@ -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); } } diff --git a/junit5/src/test/java/com/baeldung/FirstTest.java b/junit5/src/test/java/com/baeldung/FirstTest.java index c0dc6f345c..d7c6c0368f 100644 --- a/junit5/src/test/java/com/baeldung/FirstTest.java +++ b/junit5/src/test/java/com/baeldung/FirstTest.java @@ -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); + } } diff --git a/junit5/src/test/java/com/baeldung/TaggedTest.java b/junit5/src/test/java/com/baeldung/TaggedTest.java new file mode 100644 index 0000000000..5107c04037 --- /dev/null +++ b/junit5/src/test/java/com/baeldung/TaggedTest.java @@ -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); + } +}