TeeOutputStream extends OutputStream { @Override public void close() { tryWith(original, branch, (ignored, ignoredToo) -> { }); }  @Override void write(final byte[] b); @Override void write(final byte[] b, final int off, final int len); @Override void write(final int b); @Override void flush(); @Override void close();  }
@Test void shouldClose() throws IOException { unit.close(); verify(first).close(); verify(second).close(); }
@Test void shouldCloseSecondEvenIfFirstFails() throws IOException { final IOException expected = new IOException(); doThrow(expected).when(first).close(); final IOException actual = assertThrows(IOException.class, unit::close); assertSame(expected, actual); verify(second).close(); }