@Test public void whenGetResultsForRegistrationItShouldNotScoreRunsBeyondMaxPerRegistration() { when(event.getMaxRunsPerRegistration()).thenReturn(1); allRunsWithRegistration.addAll(Arrays.asList(mock(Run.class), mock(Run.class))); ScoredRun expectedScoredRun = mock(ScoredRun.class); when(runScoringInteractor.score(any())).thenReturn(expectedScoredRun); GetRegistrationResultsPayload actual = resultsService.getResultsFor(registration); assertThat(actual.getScoredRuns()).hasSize(1); assertThat(actual.getScore()).isSameAs(expectedScoredRun); verify(runScoringInteractor, Mockito.times(1)).score(any(Run.class)); }
public GetRegistrationResultsPayload getResultsFor(Registration registration) { GetRegistrationResultsPayload payload = new GetRegistrationResultsPayload(); payload.setRegistration(registration); List<Run> runs = runEntityService.getAllWithRegistration(registration); int maxRunsPerRegistration = registration.getEvent().getMaxRunsPerRegistration(); List<ScoredRun> scoredRuns = new ArrayList<>(runs.size()); for (Run run : runs) { if (scoredRuns.size() >= maxRunsPerRegistration) { break; } ScoredRun scoredRun = runScoringInteractor.score(run); if (scoredRun != null) { scoredRuns.add(scoredRun); } } payload.setScoredRuns(scoredRuns); payload.setScore(scoredRuns.stream() .min(Comparator.comparing(ScoredRun::getRawTimeScored)) .orElse(null)); return payload; }
ResultsService { public GetRegistrationResultsPayload getResultsFor(Registration registration) { GetRegistrationResultsPayload payload = new GetRegistrationResultsPayload(); payload.setRegistration(registration); List<Run> runs = runEntityService.getAllWithRegistration(registration); int maxRunsPerRegistration = registration.getEvent().getMaxRunsPerRegistration(); List<ScoredRun> scoredRuns = new ArrayList<>(runs.size()); for (Run run : runs) { if (scoredRuns.size() >= maxRunsPerRegistration) { break; } ScoredRun scoredRun = runScoringInteractor.score(run); if (scoredRun != null) { scoredRuns.add(scoredRun); } } payload.setScoredRuns(scoredRuns); payload.setScore(scoredRuns.stream() .min(Comparator.comparing(ScoredRun::getRawTimeScored)) .orElse(null)); return payload; } }
ResultsService { public GetRegistrationResultsPayload getResultsFor(Registration registration) { GetRegistrationResultsPayload payload = new GetRegistrationResultsPayload(); payload.setRegistration(registration); List<Run> runs = runEntityService.getAllWithRegistration(registration); int maxRunsPerRegistration = registration.getEvent().getMaxRunsPerRegistration(); List<ScoredRun> scoredRuns = new ArrayList<>(runs.size()); for (Run run : runs) { if (scoredRuns.size() >= maxRunsPerRegistration) { break; } ScoredRun scoredRun = runScoringInteractor.score(run); if (scoredRun != null) { scoredRuns.add(scoredRun); } } payload.setScoredRuns(scoredRuns); payload.setScore(scoredRuns.stream() .min(Comparator.comparing(ScoredRun::getRawTimeScored)) .orElse(null)); return payload; } @Inject  ResultsService(
            RunEntityService runEntityService,
            RunScoringInteractor runScoringInteractor
    ); }
ResultsService { public GetRegistrationResultsPayload getResultsFor(Registration registration) { GetRegistrationResultsPayload payload = new GetRegistrationResultsPayload(); payload.setRegistration(registration); List<Run> runs = runEntityService.getAllWithRegistration(registration); int maxRunsPerRegistration = registration.getEvent().getMaxRunsPerRegistration(); List<ScoredRun> scoredRuns = new ArrayList<>(runs.size()); for (Run run : runs) { if (scoredRuns.size() >= maxRunsPerRegistration) { break; } ScoredRun scoredRun = runScoringInteractor.score(run); if (scoredRun != null) { scoredRuns.add(scoredRun); } } payload.setScoredRuns(scoredRuns); payload.setScore(scoredRuns.stream() .min(Comparator.comparing(ScoredRun::getRawTimeScored)) .orElse(null)); return payload; } @Inject  ResultsService(
            RunEntityService runEntityService,
            RunScoringInteractor runScoringInteractor
    ); GetRegistrationResultsPayload getResultsFor(Registration registration); }
ResultsService { public GetRegistrationResultsPayload getResultsFor(Registration registration) { GetRegistrationResultsPayload payload = new GetRegistrationResultsPayload(); payload.setRegistration(registration); List<Run> runs = runEntityService.getAllWithRegistration(registration); int maxRunsPerRegistration = registration.getEvent().getMaxRunsPerRegistration(); List<ScoredRun> scoredRuns = new ArrayList<>(runs.size()); for (Run run : runs) { if (scoredRuns.size() >= maxRunsPerRegistration) { break; } ScoredRun scoredRun = runScoringInteractor.score(run); if (scoredRun != null) { scoredRuns.add(scoredRun); } } payload.setScoredRuns(scoredRuns); payload.setScore(scoredRuns.stream() .min(Comparator.comparing(ScoredRun::getRawTimeScored)) .orElse(null)); return payload; } @Inject  ResultsService(
            RunEntityService runEntityService,
            RunScoringInteractor runScoringInteractor
    ); GetRegistrationResultsPayload getResultsFor(Registration registration);  }