@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()); }
@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 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 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); }
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(); }
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();  }