ProgressControl { public void advance(long bytesRead) { totalBytesRead += bytesRead; byte percent; if (length != 0) { percent = (byte) Math.floor(((double) totalBytesRead) / length * 100); } else { percent = 100; } if (percent > lastUpdatedPercentValue && contextMap != null) { lastUpdatedPercentValue = percent; contextMap.put(attributeName, lastUpdatedPercentValue); } } ProgressControl(String uploadId, long length); static byte getProgress(FacesContext context, String uploadId); void advance(long bytesRead); void setContextMap(Map<String, Object> contextMap); ServletInputStream wrapStream(ServletInputStream inputStream);  }
@Test public void testAdvance() throws Exception { Map<String, Object> contextMap = Maps.newHashMap(); ProgressControl control = new ProgressControl(UPLOAD_ID, 400); control.setContextMap(contextMap); assertNull(contextMap.get(ATTRIBUTE_NAME)); control.advance(1); assertNull(contextMap.get(ATTRIBUTE_NAME)); control.advance(3); assertEquals((byte) 1, contextMap.get(ATTRIBUTE_NAME)); control.advance(196); assertEquals((byte) 50, contextMap.get(ATTRIBUTE_NAME)); control.advance(200); assertEquals((byte) 100, contextMap.get(ATTRIBUTE_NAME)); }