From f7176e6255e9cf3b72479e1b48d142bcf8e237f5 Mon Sep 17 00:00:00 2001 From: amedviediev Date: Wed, 11 May 2016 00:00:29 +0300 Subject: [PATCH] - Added code for JUnit 5 article --- .../src/test/java/com/baeldung/ExceptionTest.java | 6 +++--- junit5/src/test/java/com/baeldung/FirstTest.java | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/junit5/src/test/java/com/baeldung/ExceptionTest.java b/junit5/src/test/java/com/baeldung/ExceptionTest.java index 26c44e8b10..25b7f0a1cc 100644 --- a/junit5/src/test/java/com/baeldung/ExceptionTest.java +++ b/junit5/src/test/java/com/baeldung/ExceptionTest.java @@ -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"); } } diff --git a/junit5/src/test/java/com/baeldung/FirstTest.java b/junit5/src/test/java/com/baeldung/FirstTest.java index d7c6c0368f..aa7bcfdcd0 100644 --- a/junit5/src/test/java/com/baeldung/FirstTest.java +++ b/junit5/src/test/java/com/baeldung/FirstTest.java @@ -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 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);