TraditionalHandicapTimeScoringInteractor implements HandicapTimeScoringInteractor { @Override public void score(ScoredRun scoredRun) { BigDecimal rawTimeScored = scoredRun.getRawTimeScored(); Preconditions.checkNotNull(rawTimeScored, "depends on raw time scored"); Run run = scoredRun.getRun(); BigDecimal handicapGroupFactor = run.getRegistration().getHandicapGroup().getFactor(); BigDecimal competitionGroupFactor = run.getRegistration().getCompetitionGroup().getFactor(); BigDecimal handicapTimeScored = rawTimeScored.multiply(handicapGroupFactor) .multiply(competitionGroupFactor) .setScale(3, RoundingMode.HALF_UP); scoredRun.setHandicapTimeScored(handicapTimeScored); }  @Override void score(ScoredRun scoredRun);  }
@Test public void itShouldSetHandicapTimeForCleanRun() { BigDecimal rawTimeScored = BigDecimal.valueOf(100000, 3); when(scoredRun.getRawTimeScored()).thenReturn(rawTimeScored); BigDecimal expected = BigDecimal.valueOf(87600, 3); interactor.score(scoredRun); verify(scoredRun).setHandicapTimeScored(eq(expected)); }
@Test public void itShouldSetHandicapTimeForConedRun() { BigDecimal rawTimeScored = BigDecimal.valueOf(106000, 3); when(scoredRun.getRawTimeScored()).thenReturn(rawTimeScored); BigDecimal expected = BigDecimal.valueOf(92856, 3); interactor.score(scoredRun); verify(scoredRun).setHandicapTimeScored(eq(expected)); }