RunEntityService extends AbstractEntityService<
        Run,
        RunAddPayload,
        RunGateway> { public RunTimeAddedPayload addTimeToFirstRunInSequenceWithoutRawTime(RunAddTimePayload addTimePayload) throws EntityNotFoundException, AddEntityException { RunTimeAddedPayload runTimeAddedPayload = new RunTimeAddedPayload(); Run firstRunInSequenceWithoutTime = gateway.findFirstInSequenceWithoutTime(addTimePayload.getEvent()); if (firstRunInSequenceWithoutTime != null) { firstRunInSequenceWithoutTime.setRawTime(addTimePayload.getRawTime()); Run runWithRawTimeAssigned = gateway.save( firstRunInSequenceWithoutTime.getId(), firstRunInSequenceWithoutTime ); runTimeAddedPayload.setRun(runWithRawTimeAssigned); runTimeAddedPayload.setOutcome(RunTimeAddedPayload.Outcome.RUN_RAWTIME_ASSIGNED_TO_EXISTING); } else { RunAddPayload addPayload = new RunAddPayload(); addPayload.setEvent(addTimePayload.getEvent()); addPayload.setTimestamp(Instant.now()); addPayload.setRawTime(addTimePayload.getRawTime()); Run addedRun = add(addPayload); runTimeAddedPayload.setRun(addedRun); runTimeAddedPayload.setOutcome(RunTimeAddedPayload.Outcome.RUN_ADDED_WITH_RAWTIME); } return runTimeAddedPayload; } @Inject  RunEntityService(RunGateway gateway, EventEntityService eventEntityService); @Override Run add(RunAddPayload addPayload); Run getByEventIdAndRunId(String eventId, String runId); List<Run> getAllWithEventId(String eventId); RunTimeAddedPayload addTimeToFirstRunInSequenceWithoutRawTime(RunAddTimePayload addTimePayload); List<Run> getAllWithRegistration(Registration registration);  }
@Test public void whenAddToFirstRunInSequenceWithoutRawTimeWithRunLackingTime() throws AddEntityException, EntityNotFoundException { Run firstRunInSequenceWithoutRawTime = mock(Run.class); when(firstRunInSequenceWithoutRawTime.getId()).thenReturn(TestConstants.RUN_ID); when(gateway.findFirstInSequenceWithoutTime(runAddRawTimePayloadEvent)) .thenReturn(firstRunInSequenceWithoutRawTime); Run runWithRawTimeAssigned = mock(Run.class); when(gateway.save(TestConstants.RUN_ID, firstRunInSequenceWithoutRawTime)).thenReturn(runWithRawTimeAssigned); RunTimeAddedPayload actual = service.addTimeToFirstRunInSequenceWithoutRawTime(runAddRawTimePayload); verify(firstRunInSequenceWithoutRawTime).setRawTime(runAddRawTimePayloadRawTime); verify(gateway).save(TestConstants.RUN_ID, firstRunInSequenceWithoutRawTime); assertThat(actual.getOutcome()).isEqualTo(RunTimeAddedPayload.Outcome.RUN_RAWTIME_ASSIGNED_TO_EXISTING); assertThat(actual.getRun()).isSameAs(runWithRawTimeAssigned); }