Progress { public synchronized void set(float progress) { if (Float.isNaN(progress)) { progress = 0; LOG.debug("Illegal progress value found, progress is Float.NaN. " + "Progress will be changed to 0"); } else if (progress == Float.NEGATIVE_INFINITY) { progress = 0; LOG.debug("Illegal progress value found, progress is " + "Float.NEGATIVE_INFINITY. Progress will be changed to 0"); } else if (progress < 0) { progress = 0; LOG.debug("Illegal progress value found, progress is less than 0." + " Progress will be changed to 0"); } else if (progress > 1) { progress = 1; LOG.debug("Illegal progress value found, progress is larger than 1." + " Progress will be changed to 1"); } else if (progress == Float.POSITIVE_INFINITY) { progress = 1; LOG.debug("Illegal progress value found, progress is " + "Float.POSITIVE_INFINITY. Progress will be changed to 1"); } this.progress = progress; } Progress(); Progress addPhase(String status); synchronized Progress addPhase(); Progress addPhase(String status, float weightage); synchronized Progress addPhase(float weightage); synchronized void addPhases(int n); synchronized void startNextPhase(); synchronized Progress phase(); void complete(); synchronized void set(float progress); synchronized float get(); synchronized float getProgress(); synchronized void setStatus(String status); @Override String toString();  }
@Test public void testSet(){ Progress progress = new Progress(); progress.set(Float.NaN); Assert.assertEquals(0, progress.getProgress(), 0.0); progress.set(Float.NEGATIVE_INFINITY); Assert.assertEquals(0,progress.getProgress(),0.0); progress.set(-1); Assert.assertEquals(0,progress.getProgress(),0.0); progress.set((float) 1.1); Assert.assertEquals(1,progress.getProgress(),0.0); progress.set(Float.POSITIVE_INFINITY); Assert.assertEquals(1,progress.getProgress(),0.0); }