### Question:
CountingInputStream extends FilterInputStream { @Override public int read() { try { int result = checkEOF(in.read()); if (result != -1) { mCount++; } mResponseHandler.onRead(mCount); return result; } catch (IOException ex) { return 0; } } CountingInputStream(InputStream in, ResponseHandler responseHandler); @Override int read(); @Override int read(@NonNull byte[] b); @Override int read(@NonNull byte[] b, int off, int len); @Override boolean markSupported(); @Override void reset();  }### Answer:
@Test public void testOnRead() throws IOException { ResponseHandler responseHandler = mock(ResponseHandler.class); String myString = "Hello! How are you"; InputStream is = new ByteArrayInputStream(myString.getBytes()); CountingInputStream countingInputStream = new CountingInputStream(is, responseHandler); countingInputStream.read(); verify(responseHandler, timeout(1)).onRead(anyInt()); }
@Test public void testOnReadWithByte() throws IOException { ResponseHandler responseHandler = mock(ResponseHandler.class); String myString = "Hello! How are you"; InputStream is = new ByteArrayInputStream(myString.getBytes()); CountingInputStream countingInputStream = new CountingInputStream(is, responseHandler); countingInputStream.read(myString.getBytes()); verify(responseHandler, timeout(1)).onRead(anyInt()); }