private static void runFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { } }
/** @return the number of exceptions that were suppressed on the expected thrown exception */ private static int runSuppressionFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { return CloserTest.getSuppressed(expected).length; } throw new AssertionError(); // can't happen }
public void testClosesOnErrors_copyingToCharSinkThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, WRITE_THROWS, CLOSE_THROWS)) { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestCharSink(option)); fail(); } catch (IOException expected) { } // ensure reader was closed IF it was opened (depends on implementation whether or not it's // opened at all if sink.newWriter() throws). assertTrue( "stream not closed when copying to sink with option: " + option, !okSource.wasStreamOpened() || okSource.wasStreamClosed()); } }
public void testClosesOnErrors_copyingToWriterThatThrows() { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestWriter(WRITE_THROWS)); fail(); } catch (IOException expected) { } assertTrue(okSource.wasStreamClosed()); }
public void testClosesOnErrors_whenReadThrows() { TestCharSource failSource = new TestCharSource(STRING, READ_THROWS); try { failSource.copyTo(new TestCharSink()); fail(); } catch (IOException expected) { } assertTrue(failSource.wasStreamClosed()); }
private static void runFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { } }
/** * @return the number of exceptions that were suppressed on the expected thrown exception */ private static int runSuppressionFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { return CloserTest.getSuppressed(expected).length; } throw new AssertionError(); // can't happen }
public void testClosesOnErrors_copyingToCharSinkThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, WRITE_THROWS, CLOSE_THROWS)) { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestCharSink(option)); fail(); } catch (IOException expected) { } // ensure reader was closed IF it was opened (depends on implementation whether or not it's // opened at all if sink.newWriter() throws). assertTrue("stream not closed when copying to sink with option: " + option, !okSource.wasStreamOpened() || okSource.wasStreamClosed()); } }
public void testClosesOnErrors_copyingToWriterThatThrows() { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestWriter(WRITE_THROWS)); fail(); } catch (IOException expected) { } assertTrue(okSource.wasStreamClosed()); }
public void testClosesOnErrors_whenReadThrows() { TestCharSource failSource = new TestCharSource(STRING, READ_THROWS); try { failSource.copyTo(new TestCharSink()); fail(); } catch (IOException expected) { } assertTrue(failSource.wasStreamClosed()); }