public void testClosesOnErrors_writingFromInputStreamThatThrows() { TestByteSink okSink = new TestByteSink(); try { TestInputStream in = new TestInputStream(new ByteArrayInputStream(new byte[10]), READ_THROWS); okSink.writeFrom(in); fail(); } catch (IOException expected) { } assertTrue(okSink.wasStreamClosed()); } }
public void testClosesOnErrors_whenWriteThrows() { TestByteSink failSink = new TestByteSink(WRITE_THROWS); try { new TestByteSource(new byte[10]).copyTo(failSink); fail(); } catch (IOException expected) { } assertTrue(failSink.wasStreamClosed()); }
public void testClosesOnErrors_copyingFromByteSourceThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, READ_THROWS, CLOSE_THROWS)) { TestByteSource failSource = new TestByteSource(new byte[10], option); TestByteSink okSink = new TestByteSink(); try { failSource.copyTo(okSink); fail(); } catch (IOException expected) { } // ensure stream was closed IF it was opened (depends on implementation whether or not it's // opened at all if source.newInputStream() throws). assertTrue( "stream not closed when copying from source with option: " + option, !okSink.wasStreamOpened() || okSink.wasStreamClosed()); } }
public void testClosesOnErrors_writingFromInputStreamThatThrows() { TestByteSink okSink = new TestByteSink(); try { TestInputStream in = new TestInputStream( new ByteArrayInputStream(new byte[10]), READ_THROWS); okSink.writeFrom(in); fail(); } catch (IOException expected) { } assertTrue(okSink.wasStreamClosed()); } }
public void testClosesOnErrors_copyingFromByteSourceThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, READ_THROWS, CLOSE_THROWS)) { TestByteSource failSource = new TestByteSource(new byte[10], option); TestByteSink okSink = new TestByteSink(); try { failSource.copyTo(okSink); fail(); } catch (IOException expected) {} // ensure stream was closed IF it was opened (depends on implementation whether or not it's // opened at all if source.newInputStream() throws). assertTrue("stream not closed when copying from source with option: " + option, !okSink.wasStreamOpened() || okSink.wasStreamClosed()); } }
public void testClosesOnErrors_whenWriteThrows() { TestByteSink failSink = new TestByteSink(WRITE_THROWS); try { new TestByteSource(new byte[10]).copyTo(failSink); fail(); } catch (IOException expected) { } assertTrue(failSink.wasStreamClosed()); }