- Added code for JUnit 5 article

This commit is contained in:
amedviediev 2016-05-02 13:00:21 +03:00
parent c574b94ea3
commit a875e25b18
4 changed files with 31 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package com.baeldung;
import org.junit.gen5.api.Test; 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.assumeFalse;
import static org.junit.gen5.api.Assumptions.assumeTrue; import static org.junit.gen5.api.Assumptions.assumeTrue;
import static org.junit.gen5.api.Assumptions.assumingThat; import static org.junit.gen5.api.Assumptions.assumingThat;
@ -11,13 +12,13 @@ public class AssumptionTest {
@Test @Test
void trueAssumption() { void trueAssumption() {
assumeTrue(5 > 1); assumeTrue(5 > 1);
System.out.println("Was true"); assertEquals(5 + 2, 7);
} }
@Test @Test
void falseAssumption() { void falseAssumption() {
assumeFalse(5 < 1); assumeFalse(5 < 1);
System.out.println("Was false"); assertEquals(5 + 2, 7);
} }
@Test @Test
@ -25,7 +26,7 @@ public class AssumptionTest {
String someString = "Just a string"; String someString = "Just a string";
assumingThat( assumingThat(
someString.equals("Just a string"), someString.equals("Just a string"),
() -> System.out.println("Assumption was correct") () -> assertEquals(2 + 2, 4)
); );
} }
} }

View File

@ -2,6 +2,8 @@ package com.baeldung;
import org.junit.gen5.api.Test; 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.assertEquals;
import static org.junit.gen5.api.Assertions.expectThrows; import static org.junit.gen5.api.Assertions.expectThrows;
@ -9,7 +11,8 @@ public class ExceptionTest {
@Test @Test
void shouldThrowException() { void shouldThrowException() {
Throwable exception = expectThrows(NullPointerException.class, null); ArrayList list = null;
Throwable exception = expectThrows(NullPointerException.class, list::clear);
assertEquals(exception.getClass(), NullPointerException.class); assertEquals(exception.getClass(), NullPointerException.class);
} }
} }

View File

@ -1,5 +1,6 @@
package com.baeldung; package com.baeldung;
import org.junit.gen5.api.Disabled;
import org.junit.gen5.api.Test; import org.junit.gen5.api.Test;
import static org.junit.gen5.api.Assertions.assertAll; import static org.junit.gen5.api.Assertions.assertAll;
@ -11,7 +12,7 @@ class FirstTest {
@Test @Test
void lambdaExpressions() { void lambdaExpressions() {
String string = ""; String string = "";
assertTrue(() -> string.isEmpty(), "String should be empty"); assertTrue(string::isEmpty, "String should be empty");
} }
@Test @Test
@ -24,4 +25,9 @@ class FirstTest {
}); });
} }
@Test
@Disabled
void disabledTest() {
assertTrue(false);
}
} }

View File

@ -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);
}
}