Skip to content

Commit a875e25

Browse files
committed
- Added code for JUnit 5 article
1 parent c574b94 commit a875e25

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎junit5/src/test/java/com/baeldung/AssumptionTest.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.gen5.api.Test;
44

5+
import static org.junit.gen5.api.Assertions.assertEquals;
56
import static org.junit.gen5.api.Assumptions.assumeFalse;
67
import static org.junit.gen5.api.Assumptions.assumeTrue;
78
import static org.junit.gen5.api.Assumptions.assumingThat;
@@ -11,21 +12,21 @@ public class AssumptionTest {
1112
@Test
1213
void trueAssumption() {
1314
assumeTrue(5 > 1);
14-
System.out.println("Was true");
15+
assertEquals(5 + 2, 7);
1516
}
1617

1718
@Test
1819
void falseAssumption() {
1920
assumeFalse(5 < 1);
20-
System.out.println("Was false");
21+
assertEquals(5 + 2, 7);
2122
}
2223

2324
@Test
2425
void assumptionThat() {
2526
String someString = "Just a string";
2627
assumingThat(
2728
someString.equals("Just a string"),
28-
() -> System.out.println("Assumption was correct")
29+
() -> assertEquals(2 + 2, 4)
2930
);
3031
}
3132
}

‎junit5/src/test/java/com/baeldung/ExceptionTest.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
import org.junit.gen5.api.Test;
44

5+
import java.util.ArrayList;
6+
57
import static org.junit.gen5.api.Assertions.assertEquals;
68
import static org.junit.gen5.api.Assertions.expectThrows;
79

810
public class ExceptionTest {
911

1012
@Test
1113
void shouldThrowException() {
12-
Throwable exception = expectThrows(NullPointerException.class, null);
14+
ArrayList list = null;
15+
Throwable exception = expectThrows(NullPointerException.class, list::clear);
1316
assertEquals(exception.getClass(), NullPointerException.class);
1417
}
1518
}

‎junit5/src/test/java/com/baeldung/FirstTest.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.baeldung;
22

3+
import org.junit.gen5.api.Disabled;
34
import org.junit.gen5.api.Test;
45

56
import static org.junit.gen5.api.Assertions.assertAll;
@@ -11,7 +12,7 @@ class FirstTest {
1112
@Test
1213
void lambdaExpressions() {
1314
String string = "";
14-
assertTrue(() -> string.isEmpty(), "String should be empty");
15+
assertTrue(string::isEmpty, "String should be empty");
1516
}
1617

1718
@Test
@@ -24,4 +25,9 @@ void groupAssertions() {
2425
});
2526
}
2627

28+
@Test
29+
@Disabled
30+
void disabledTest() {
31+
assertTrue(false);
32+
}
2733
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung;
2+
3+
import org.junit.gen5.api.Tag;
4+
import org.junit.gen5.api.Test;
5+
6+
import static org.junit.gen5.api.Assertions.assertEquals;
7+
8+
@Tag("Test case")
9+
public class TaggedTest {
10+
11+
@Test
12+
@Tag("Method")
13+
void testMethod() {
14+
assertEquals(2+2, 4);
15+
}
16+
}

0 commit comments

Comments
 (0)