public void testClosesOnErrors_whenWriteThrows() { TestCharSink failSink = new TestCharSink(WRITE_THROWS); try { new TestCharSource(STRING).copyTo(failSink); fail(); } catch (IOException expected) { } assertTrue(failSink.wasStreamClosed()); }
public void testClosesOnErrors_copyingFromCharSourceThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, READ_THROWS, CLOSE_THROWS)) { TestCharSource failSource = new TestCharSource(STRING, option); TestCharSink okSink = new TestCharSink(); try { failSource.copyTo(okSink); fail(); } catch (IOException expected) { } // ensure writer was closed IF it was opened (depends on implementation whether or not it's // opened at all if source.newReader() throws). assertTrue( "stream not closed when copying from source with option: " + option, !okSink.wasStreamOpened() || okSink.wasStreamClosed()); } }
public void testClosesOnErrors_whenWritingFromReaderThatThrows() { TestCharSink okSink = new TestCharSink(); try { okSink.writeFrom(new TestReader(READ_THROWS)); fail(); } catch (IOException expected) { } assertTrue(okSink.wasStreamClosed()); } }
public void testClosesOnErrors_whenWritingFromReaderThatThrows() { TestCharSink okSink = new TestCharSink(); try { okSink.writeFrom(new TestReader(READ_THROWS)); fail(); } catch (IOException expected) { } assertTrue(okSink.wasStreamClosed()); } }
public void testClosesOnErrors_copyingFromCharSourceThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, READ_THROWS, CLOSE_THROWS)) { TestCharSource failSource = new TestCharSource(STRING, option); TestCharSink okSink = new TestCharSink(); try { failSource.copyTo(okSink); fail(); } catch (IOException expected) { } // ensure writer was closed IF it was opened (depends on implementation whether or not it's // opened at all if source.newReader() throws). assertTrue("stream not closed when copying from source with option: " + option, !okSink.wasStreamOpened() || okSink.wasStreamClosed()); } }
public void testClosesOnErrors_whenWriteThrows() { TestCharSink failSink = new TestCharSink(WRITE_THROWS); try { new TestCharSource(STRING).copyTo(failSink); fail(); } catch (IOException expected) { } assertTrue(failSink.wasStreamClosed()); }