- Added code for JUnit 5 article

This commit is contained in:
amedviediev 2016-05-11 00:00:29 +03:00
parent a875e25b18
commit f7176e6255
2 changed files with 13 additions and 6 deletions

View File

@ -11,8 +11,8 @@ public class ExceptionTest {
@Test
void shouldThrowException() {
ArrayList list = null;
Throwable exception = expectThrows(NullPointerException.class, list::clear);
assertEquals(exception.getClass(), NullPointerException.class);
Throwable exception = expectThrows(UnsupportedOperationException.class,
() -> {throw new UnsupportedOperationException("Not supported");});
assertEquals(exception.getMessage(), "Not supported");
}
}

View File

@ -3,6 +3,10 @@ package com.baeldung;
import org.junit.gen5.api.Disabled;
import org.junit.gen5.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.gen5.api.Assertions.assertAll;
import static org.junit.gen5.api.Assertions.assertEquals;
import static org.junit.gen5.api.Assertions.assertTrue;
@ -11,13 +15,16 @@ class FirstTest {
@Test
void lambdaExpressions() {
String string = "";
assertTrue(string::isEmpty, "String should be empty");
List<Integer> numbers = Arrays.asList(1, 2, 3);
assertTrue(numbers
.stream()
.mapToInt(i -> i)
.sum() > 5, "Sum should be greater than 5");
}
@Test
void groupAssertions() {
int[] numbers = {0,1,2,3,4};
int[] numbers = {0, 1, 2, 3, 4};
assertAll("numbers", () -> {
assertEquals(numbers[0], 1);
assertEquals(numbers[3], 3);