### Question:
B2InputStreamWithByteProgressListener extends InputStream { @Override public int available() throws IOException { try { return inputStream.available(); } 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 testAvailable() throws Exception { when(wrappedStream.available()).thenReturn(6); assertEquals(6, stream.available()); verify(wrappedStream, times(1)).available(); }
@Test public void testAvailable_throwsIOException() throws Exception { final IOException exception = new IOException("test"); when(wrappedStream.available()).thenThrow(exception); try { stream.available(); fail("should've thrown!"); } catch (IOException e) { assertEquals("test", e.getMessage()); } verify(wrappedStream, times(1)).available(); verify(listener, times(1)).hitException(eq(exception), eq(0L)); }
@Test public void testAvailable_throwsRuntimeException() throws Exception { final RuntimeException exception = new RuntimeException("test"); when(wrappedStream.available()).thenThrow(exception); try { stream.available(); fail("should've thrown!"); } catch (RuntimeException e) { assertEquals("test", e.getMessage()); } verify(wrappedStream, times(1)).available(); verify(listener, times(1)).hitException(eq(exception), eq(0L)); }