Skip to content

Commit f7176e6

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

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class ExceptionTest {
1111

1212
@Test
1313
void shouldThrowException() {
14-
ArrayList list = null;
15-
Throwable exception = expectThrows(NullPointerException.class, list::clear);
16-
assertEquals(exception.getClass(), NullPointerException.class);
14+
Throwable exception = expectThrows(UnsupportedOperationException.class,
15+
() -> {throw new UnsupportedOperationException("Not supported");});
16+
assertEquals(exception.getMessage(), "Not supported");
1717
}
1818
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import org.junit.gen5.api.Disabled;
44
import org.junit.gen5.api.Test;
55

6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
610
import static org.junit.gen5.api.Assertions.assertAll;
711
import static org.junit.gen5.api.Assertions.assertEquals;
812
import static org.junit.gen5.api.Assertions.assertTrue;
@@ -11,13 +15,16 @@ class FirstTest {
1115

1216
@Test
1317
void lambdaExpressions() {
14-
String string = "";
15-
assertTrue(string::isEmpty, "String should be empty");
18+
List<Integer> numbers = Arrays.asList(1, 2, 3);
19+
assertTrue(numbers
20+
.stream()
21+
.mapToInt(i -> i)
22+
.sum() > 5, "Sum should be greater than 5");
1623
}
1724

1825
@Test
1926
void groupAssertions() {
20-
int[] numbers = {0,1,2,3,4};
27+
int[] numbers = {0, 1, 2, 3, 4};
2128
assertAll("numbers", () -> {
2229
assertEquals(numbers[0], 1);
2330
assertEquals(numbers[3], 3);

0 commit comments

Comments
 (0)