Java Code Examples for java.io.IOException#equals()

The following examples show how to use java.io.IOException#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RsPrintTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * RsPrint can flush body contents even when exception happens.
 * @throws IOException If some problem inside
 */
@Test
public void flushBodyEvenWhenExceptionHappens() throws IOException {
    final IOException exception = new IOException("Failure");
    final FailOutputStream output = new FailOutputStream(exception);
    try {
        new RsPrint(new RsText("Hello"))
            .printBody(output);
    } catch (final IOException ex) {
        if (!ex.equals(exception)) {
            throw ex;
        }
    }
    MatcherAssert.assertThat(
        output.haveFlushed(),
        Matchers.is(true)
    );
}
 
Example 2
Source File: RsPrintTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * RsPrint can close body contents even when exception happens.
 * @throws IOException If some problem inside
 */
@Test
public void closeBodyEvenWhenExceptionHappens() throws IOException {
    final IOException exception = new IOException("Smth went wrong");
    final FailOutputStream output = new FailOutputStream(exception);
    final FakeInput input = new FakeInput(new InputStreamOf("abc"));
    try {
        new RsPrint(new RsText(input))
            .printBody(output);
    } catch (final IOException ex) {
        if (!ex.equals(exception)) {
            throw ex;
        }
    }
    MatcherAssert.assertThat(
        "Input body was not closed",
        input.isClosed(),
        new IsEqual<>(true)
    );
}
 
Example 3
Source File: RsPrintTest.java    From takes with MIT License 6 votes vote down vote up
/**
 * RsPrint can flush head contents even when exception happens.
 * @throws IOException If some problem inside
 */
@Test
public void flushHeadEvenWhenExceptionHappens() throws IOException {
    final IOException exception = new IOException("Error");
    final FailWriter writer = new FailWriter(exception);
    try {
        new RsPrint(new RsText("World!"))
            .printHead(writer);
    } catch (final IOException ex) {
        if (!ex.equals(exception)) {
            throw ex;
        }
    }
    MatcherAssert.assertThat(
        writer.haveFlushed(),
        Matchers.is(true)
    );
}