ProgressTracker { void onBytesRead(final long bytesRead) { totalBytesRead += bytesRead; if (totalBytesRead < 0 || totalBytesRead > totalBytes) { throw new IllegalStateException( String.format( "IllegalState - bytes read %d causes total bytes read(%d) > total bytes(%d)", bytesRead, totalBytesRead, totalBytes)); } progressReporter.onProgress(totalBytesRead, totalBytes); }    }
@Test(expected = IllegalStateException.class) public void illegalProgressReport_overflow() { ProgressTrackerFactory progressTrackerFactory = ProgressTrackerFactory.createSingleUploadProgressTrackerFactory( new ProgressReporter() { @Override public void onProgress(long completed, long total) {} }, 0L); progressTrackerFactory.getProgressTracker().onBytesRead(READ_CHUNK_SIZE); }
@Test(expected = IllegalStateException.class) public void illegalProgressReport_underflow() { ProgressTrackerFactory progressTrackerFactory = ProgressTrackerFactory.createSingleUploadProgressTrackerFactory( new ProgressReporter() { @Override public void onProgress(long completed, long total) {} }, 0L); progressTrackerFactory.getProgressTracker().onBytesRead(-1); }