@Test
public void testReportingFirstExceptionAndSuppressingLaterOnClose() throws Exception {

    IOException closingException = new IOException("stream close exception");
    IOException closingException2 = new IOException("stream close exception for stream c");
    IOException closingException3 = new IOException("stream close exception for stream d");
    InputStream a = mock(InputStream.class);
    InputStream b = mock(InputStream.class);
    doThrow(closingException).when(b).close();
    InputStream c = mock(InputStream.class);
    doThrow(closingException2).when(c).close();
    InputStream d = mock(InputStream.class);
    doThrow(closingException3).when(d).close();
    ImmutableList<InputStream> inputStreams = ImmutableList.of(a, b, c, d);
    ConcatClosingInputStream concatClosingInputStream = new ConcatClosingInputStream(inputStreams.iterator());
    try {
        concatClosingInputStream.close();
    } catch (IOException e) {
        assertSame(closingException, e);
        // when reading we get the closing exception as suppressed
        assertThat(e.getSuppressed(),
                is(arrayContaining((Throwable) closingException2, closingException3)));
    }
    verify(a).close();
    verify(b).close();
    verify(c).close();
    verify(d).close();
    verifyNoMoreInteractions(a, b, c, d);
}