@Test public void testCallsSkipOnWrapped() throws IOException { long toSkip = 67; long expected = 55; when(wrapped.skip(eq(toSkip))).thenReturn(expected); assertEquals(expected, is.skip(toSkip)); }
@Test(expected = IOException.class) public void testSkipThrowsIfStreamIsClosed() throws IOException { stream.close(); stream.skip(10); }
@Test public void testCatchesExceptionOnSkip() throws IOException { IOException exception = new SocketTimeoutException(); when(wrapped.skip(anyLong())).thenThrow(exception); long skipped = is.skip(100); assertEquals(0, skipped); assertEquals(exception, is.getException()); }
@Test public void testSkipReturnsZeroIfSkipByteCountIsZero() throws IOException { assertEquals(0, stream.skip(0)); assertEquals(0, stream.read()); }
@Test public void testSkipReturnsZeroIfSkipByteCountIsNegative() throws IOException { assertEquals(0, stream.skip(-13)); assertEquals(0, stream.read()); }
@Test public void testCanSkipBytes() throws IOException { int toSkip = data.length / 2; assertEquals(toSkip, stream.skip(toSkip)); for (int i = toSkip; i < data.length; i++) { assertEquals(i, stream.read()); } assertEquals(-1, stream.read()); }