RunScoringInteractor { public ScoredRun score(Run run) { if (!shouldScore(run)) { return null; } ScoredRun scoredRun = new ScoredRun(); scoredRun.setRun(run); if (!run.getDidNotFinish()) { rawTimeScoringInteractor.score(scoredRun); HandicapTimeScoringMethod handicapTimeScoringMethod = run.getEvent().getHandicapTimeScoringMethod(); if (handicapTimeScoringInteractors.containsKey(handicapTimeScoringMethod)) { handicapTimeScoringInteractors.get(handicapTimeScoringMethod) .score(scoredRun); } else { throw new UnsupportedOperationException( "Unsupported HandicapTimeScoringMethod: " + handicapTimeScoringMethod ); } } else { scoredRun.setRawTimeScored(TIME_DID_NOT_FINISH); scoredRun.setHandicapTimeScored(TIME_DID_NOT_FINISH); } return scoredRun; } @Inject  RunScoringInteractor(
            RawTimeScoringInteractor rawTimeScoringInteractor,
            Map<HandicapTimeScoringMethod, HandicapTimeScoringInteractor> handicapTimeScoringInteractors
    ); ScoredRun score(Run run); static final BigDecimal TIME_DID_NOT_FINISH; }
@Test public void itShouldNotScoreNullRun() { run = null; ScoredRun actual = interactor.score(run); assertThat(actual).isNull(); verifyZeroInteractions(rawTimeScoringInteractor, handicapTimeScoringInteractor); }
@Test public void itShouldNotScoreRunWithoutRawTime() { when(run.getRawTime()).thenReturn(null); ScoredRun actual = interactor.score(run); assertThat(actual).isNull(); verifyZeroInteractions(rawTimeScoringInteractor, handicapTimeScoringInteractor); }
@Test public void itShouldNotScoreRunWithRerun() { when(run.getRawTime()).thenReturn(TestConstants.RUN_RAW_TIME); when(run.getRerun()).thenReturn(true); ScoredRun actual = interactor.score(run); assertThat(actual).isNull(); verifyZeroInteractions(rawTimeScoringInteractor, handicapTimeScoringInteractor); }
@Test public void itShouldNotScoreRunWithoutCompetitive() { when(run.getRawTime()).thenReturn(TestConstants.RUN_RAW_TIME); when(run.getRerun()).thenReturn(false); when(run.getCompetitive()).thenReturn(false); ScoredRun actual = interactor.score(run); assertThat(actual).isNull(); verifyZeroInteractions(rawTimeScoringInteractor, handicapTimeScoringInteractor); }
@Test public void itShouldNotScoreRunWithDisqualified() { when(run.getRawTime()).thenReturn(TestConstants.RUN_RAW_TIME); when(run.getRerun()).thenReturn(false); when(run.getCompetitive()).thenReturn(true); when(run.getDisqualified()).thenReturn(true); ScoredRun actual = interactor.score(run); assertThat(actual).isNull(); verifyZeroInteractions(rawTimeScoringInteractor, handicapTimeScoringInteractor); }
@Test public void itShouldScoreRunWithoutDidNotFinish() { run = DomainEntityTestUtils.fullRun(); ScoredRun actual = interactor.score(run); verify(rawTimeScoringInteractor).score(actual); verify(handicapTimeScoringInteractor).score(actual); assertThat(actual.getRun()).isSameAs(run); }
@Test public void itShouldScoreRunWithDidNotFinish() { run = DomainEntityTestUtils.fullRun(); run.setDidNotFinish(true); ScoredRun actual = interactor.score(run); verifyZeroInteractions(rawTimeScoringInteractor, handicapTimeScoringInteractor); assertThat(actual) .extracting(ScoredRun::getRawTimeScored, ScoredRun::getHandicapTimeScored) .containsExactly(RunScoringInteractor.TIME_DID_NOT_FINISH, RunScoringInteractor.TIME_DID_NOT_FINISH); }