private static void runFailureTest(ByteSource in, ByteSink 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(ByteSource in, ByteSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { return CloserTest.getSuppressed(expected).length; } throw new AssertionError(); // can't happen }
public void testClosesOnErrors_copyingToByteSinkThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, WRITE_THROWS, CLOSE_THROWS)) { TestByteSource okSource = new TestByteSource(bytes); try { okSource.copyTo(new TestByteSink(option)); fail(); } catch (IOException expected) { } // ensure stream was closed IF it was opened (depends on implementation whether or not it's // opened at all if sink.newOutputStream() throws). assertTrue( "stream not closed when copying to sink with option: " + option, !okSource.wasStreamOpened() || okSource.wasStreamClosed()); } }
public void testClosesOnErrors_whenReadThrows() { TestByteSource failSource = new TestByteSource(bytes, READ_THROWS); try { failSource.copyTo(new TestByteSink()); fail(); } catch (IOException expected) { } assertTrue(failSource.wasStreamClosed()); }
public void testClosesOnErrors_copyingToOutputStreamThatThrows() { TestByteSource okSource = new TestByteSource(bytes); try { OutputStream out = new TestOutputStream(ByteStreams.nullOutputStream(), WRITE_THROWS); okSource.copyTo(out); fail(); } catch (IOException expected) { } assertTrue(okSource.wasStreamClosed()); }
public void testSlice() throws IOException { // Test preconditions try { source.slice(-1, 10); fail(); } catch (IllegalArgumentException expected) { } try { source.slice(0, -1); fail(); } catch (IllegalArgumentException expected) { } assertCorrectSlice(0, 0, 0, 0); assertCorrectSlice(0, 0, 1, 0); assertCorrectSlice(100, 0, 10, 10); assertCorrectSlice(100, 0, 100, 100); assertCorrectSlice(100, 5, 10, 10); assertCorrectSlice(100, 5, 100, 95); assertCorrectSlice(100, 100, 0, 0); assertCorrectSlice(100, 100, 10, 0); assertCorrectSlice(100, 101, 10, 0); }
private static void runFailureTest(ByteSource in, ByteSink 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(ByteSource in, ByteSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { return CloserTest.getSuppressed(expected).length; } throw new AssertionError(); // can't happen }
public void testClosesOnErrors_copyingToByteSinkThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, WRITE_THROWS, CLOSE_THROWS)) { TestByteSource okSource = new TestByteSource(bytes); try { okSource.copyTo(new TestByteSink(option)); fail(); } catch (IOException expected) { } // ensure stream was closed IF it was opened (depends on implementation whether or not it's // opened at all if sink.newOutputStream() throws). assertTrue("stream not closed when copying to sink with option: " + option, !okSource.wasStreamOpened() || okSource.wasStreamClosed()); } }
public void testClosesOnErrors_whenReadThrows() { TestByteSource failSource = new TestByteSource(bytes, READ_THROWS); try { failSource.copyTo(new TestByteSink()); fail(); } catch (IOException expected) { } assertTrue(failSource.wasStreamClosed()); }
public void testClosesOnErrors_copyingToOutputStreamThatThrows() { TestByteSource okSource = new TestByteSource(bytes); try { OutputStream out = new TestOutputStream(ByteStreams.nullOutputStream(), WRITE_THROWS); okSource.copyTo(out); fail(); } catch (IOException expected) { } assertTrue(okSource.wasStreamClosed()); }
public void testSlice() throws IOException { // Test preconditions try { source.slice(-1, 10); fail(); } catch (IllegalArgumentException expected) { } try { source.slice(0, -1); fail(); } catch (IllegalArgumentException expected) { } assertCorrectSlice(0, 0, 0, 0); assertCorrectSlice(0, 0, 1, 0); assertCorrectSlice(100, 0, 10, 10); assertCorrectSlice(100, 0, 100, 100); assertCorrectSlice(100, 5, 10, 10); assertCorrectSlice(100, 5, 100, 95); assertCorrectSlice(100, 100, 0, 0); assertCorrectSlice(100, 100, 10, 0); assertCorrectSlice(100, 101, 10, 0); }