From 98b24101b1d9cc10bee742448852f2eb59b94f2d Mon Sep 17 00:00:00 2001 From: vladhanzha Date: Wed, 17 Apr 2019 13:51:19 +0300 Subject: [PATCH] (#1062) Check exceptions in Assertion --- .../org/cactoos/func/IoCheckedBiProcTest.java | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/cactoos/func/IoCheckedBiProcTest.java b/src/test/java/org/cactoos/func/IoCheckedBiProcTest.java index be1835551a..6caa29198f 100644 --- a/src/test/java/org/cactoos/func/IoCheckedBiProcTest.java +++ b/src/test/java/org/cactoos/func/IoCheckedBiProcTest.java @@ -23,10 +23,12 @@ */ package org.cactoos.func; -import java.io.IOException; import org.hamcrest.core.IsEqual; import org.junit.Test; import org.llorllale.cactoos.matchers.Assertion; +import org.llorllale.cactoos.matchers.Throws; + +import java.io.IOException; /** * Test case for {@link IoCheckedBiFunc}. @@ -34,13 +36,25 @@ * @checkstyle JavadocMethodCheck (500 lines) */ public final class IoCheckedBiProcTest { - @Test(expected = IOException.class) - public void wrapsExceptions() throws IOException { - new IoCheckedBiProc<>( + @Test + public void wrapsExceptions() { + IoCheckedBiProc proc = new IoCheckedBiProc<>( (first, second) -> { throw new Exception(); } - ).exec(true, true); + ); + + new Assertion<>( + "Must wrap with IOException", + () -> { + proc.exec(true, true); + return true; + }, + new Throws<>( + "java.lang.Exception", + IOException.class + ) + ).affirm(); } @Test @@ -61,12 +75,24 @@ public void rethrowsIoException() { } } - @Test(expected = IllegalStateException.class) - public void runtimeExceptionGoesOut() throws IOException { - new IoCheckedBiProc<>( + @Test + public void runtimeExceptionGoesOut() { + IoCheckedBiProc proc = new IoCheckedBiProc<>( (fst, scd) -> { throw new IllegalStateException("intended to fail here"); } - ).exec(1, 2); + ); + + new Assertion<>( + "Must re-throw runtime exceptions", + () -> { + proc.exec(true, true); + return true; + }, + new Throws<>( + "intended to fail here", + IllegalStateException.class + ) + ).affirm(); } }