Skip to content

Commit

Permalink
(#1062) Add test for nominal behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
vladhss committed Apr 17, 2019
1 parent 98b2410 commit e062780
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/test/java/org/cactoos/func/IoCheckedBiProcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,39 @@
*/
package org.cactoos.func;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
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
public void executesWrappedProc() throws Exception {
final AtomicInteger counter = new AtomicInteger();
new IoCheckedBiProc<>(
(first, second) -> counter.incrementAndGet()
).exec(true, true);
new Assertion<>(
"Must execute wrapped proc",
counter::get,
new IsEqual<>(1)
).affirm();
}

@Test
public void wrapsExceptions() {
IoCheckedBiProc<Object, Object> proc = new IoCheckedBiProc<>(
final IoCheckedBiProc<Object, Object> proc = new IoCheckedBiProc<>(
(first, second) -> {
throw new Exception();
}
);

new Assertion<>(
"Must wrap with IOException",
() -> {
Expand Down Expand Up @@ -77,20 +89,20 @@ public void rethrowsIoException() {

@Test
public void runtimeExceptionGoesOut() {
IoCheckedBiProc<Object, Object> proc = new IoCheckedBiProc<>(
final String msg = "intended to fail here";
final IoCheckedBiProc<Object, Object> proc = new IoCheckedBiProc<>(
(fst, scd) -> {
throw new IllegalStateException("intended to fail here");
throw new IllegalStateException(msg);
}
);

new Assertion<>(
"Must re-throw runtime exceptions",
() -> {
proc.exec(true, true);
return true;
},
new Throws<>(
"intended to fail here",
msg,
IllegalStateException.class
)
).affirm();
Expand Down

0 comments on commit e062780

Please sign in to comment.