### Question:
B2InputStreamWithByteProgressListener extends InputStream { @Override public long skip(long n) throws IOException { try { long nReadOrEof = inputStream.skip(n); notifyListenerOfRead(nReadOrEof); return nReadOrEof; } catch (IOException | RuntimeException e) { listener.hitException(e, nBytesSoFar); throw e; } } B2InputStreamWithByteProgressListener(InputStream inputStream,
                                                 B2ByteProgressListener listener); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b,
                    int off,
                    int len); @Override long skip(long n); @Override int available(); @Override void close();  }### Answer:
@Test public void testSkip_throwsIOException() throws Exception { final IOException exception = new IOException("test"); when(wrappedStream.skip(anyLong())).thenThrow(exception); try { stream.skip(6); fail("should've thrown!"); } catch (IOException e) { assertEquals("test", e.getMessage()); } verify(wrappedStream, times(1)).skip(6); verify(listener, times(1)).hitException(eq(exception), eq(0L)); }
@Test public void testSkip_throwsRuntimeException() throws Exception { final RuntimeException exception = new RuntimeException("test"); when(wrappedStream.skip(anyLong())).thenThrow(exception); try { stream.skip(6); fail("should've thrown!"); } catch (RuntimeException e) { assertEquals("test", e.getMessage()); } verify(wrappedStream, times(1)).skip(6); verify(listener, times(1)).hitException(eq(exception), eq(0L)); }
@Test public void testSkip() throws Exception { when(wrappedStream.skip(6)).thenReturn(3L); assertEquals(3L, stream.skip(6)); verify(wrappedStream, times(1)).skip(6); verify(listener, times(1)).progress(3); }
@Test public void testSkip_getEof() throws Exception { when(wrappedStream.skip(anyLong())).thenReturn((long) EOF); assertEquals(EOF, stream.skip(6)); verify(wrappedStream, times(1)).skip(6); verify(listener, times(1)).reachedEof(0); }