DurationCalculator { public long calculateNewDuration(ViscosityInterpolator viscosity, long timesAnimationViewed, long currentDuration) { if (currentDuration == 0) { Log.e("duration was zero"); return 0; } if (timesAnimationViewed == 0) { Log.v("first time viewing so no duration change"); return currentDuration; } return viscosity.calculateDuration(currentDuration, timesAnimationViewed); }  long calculateNewDuration(ViscosityInterpolator viscosity, long timesAnimationViewed, long currentDuration);  }
@Test public void givenActHasDurationZeroWhenDurationCalculatedThenCalculatedDurationIsZero() throws Exception { long currentDuration = 0L; long duration = calc.calculateNewDuration(mockViscosity, 0, currentDuration); assertThat(duration).isEqualTo(0L); }
@Test public void givenActViewedForFirstTimeWhenDurationCalculatedThenCalculatedDurationIsCurrentDuration() throws Exception { long currentDuration = 50L; long duration = calc.calculateNewDuration(mockViscosity, 0, currentDuration); assertThat(duration).isEqualTo(currentDuration); }
@Test public void givenAnActWhenDurationCalculatedThenCalculatedDurationIsDelegatedToTheViscosity() throws Exception { int timesTransitionViewed = 1; long currentDuration = 50L; calc.calculateNewDuration(mockViscosity, timesTransitionViewed, currentDuration); verify(mockViscosity).calculateDuration(currentDuration, timesTransitionViewed); }