Skip to content

Commit

Permalink
(#1062) Check exceptions in Assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Umbrah committed Apr 17, 2019
1 parent 7b026c2 commit 98b2410
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/test/java/org/cactoos/func/IoCheckedBiProcTest.java
Expand Up @@ -23,24 +23,38 @@
*/
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}.
* @since 1.0
* @checkstyle JavadocMethodCheck (500 lines)
*/
public final class IoCheckedBiProcTest {
@Test(expected = IOException.class)
public void wrapsExceptions() throws IOException {
new IoCheckedBiProc<>(
@Test
public void wrapsExceptions() {
IoCheckedBiProc<Object, Object> 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
Expand All @@ -61,12 +75,24 @@ public void rethrowsIoException() {
}
}

@Test(expected = IllegalStateException.class)
public void runtimeExceptionGoesOut() throws IOException {
new IoCheckedBiProc<>(
@Test
public void runtimeExceptionGoesOut() {
IoCheckedBiProc<Object, Object> 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();
}
}

0 comments on commit 98b2410

Please sign in to comment.