@Test public void whenAddRunWithEventNoPriorRunsItShouldSetSequence() throws AddEntityException { when(gateway.findLastInSequenceForEvent(addPayloadEvent)).thenReturn(null); when(gateway.add(addPayload)).thenReturn(addedRun); Run actual = service.add(addPayload); verify(addPayload).setSequence(1); verify(gateway).add(addPayload); assertThat(actual).isSameAs(addedRun); }
@Override public Run add(RunAddPayload addPayload) throws AddEntityException { Run lastInSequenceForEvent = gateway.findLastInSequenceForEvent(addPayload.getEvent()); addPayload.setSequence( 1 + (lastInSequenceForEvent != null ? lastInSequenceForEvent.getSequence() : 0) ); return gateway.add(addPayload); }
RunEntityService extends AbstractEntityService<
        Run,
        RunAddPayload,
        RunGateway> { @Override public Run add(RunAddPayload addPayload) throws AddEntityException { Run lastInSequenceForEvent = gateway.findLastInSequenceForEvent(addPayload.getEvent()); addPayload.setSequence( 1 + (lastInSequenceForEvent != null ? lastInSequenceForEvent.getSequence() : 0) ); return gateway.add(addPayload); } }
RunEntityService extends AbstractEntityService<
        Run,
        RunAddPayload,
        RunGateway> { @Override public Run add(RunAddPayload addPayload) throws AddEntityException { Run lastInSequenceForEvent = gateway.findLastInSequenceForEvent(addPayload.getEvent()); addPayload.setSequence( 1 + (lastInSequenceForEvent != null ? lastInSequenceForEvent.getSequence() : 0) ); return gateway.add(addPayload); } @Inject  RunEntityService(RunGateway gateway, EventEntityService eventEntityService); }
RunEntityService extends AbstractEntityService<
        Run,
        RunAddPayload,
        RunGateway> { @Override public Run add(RunAddPayload addPayload) throws AddEntityException { Run lastInSequenceForEvent = gateway.findLastInSequenceForEvent(addPayload.getEvent()); addPayload.setSequence( 1 + (lastInSequenceForEvent != null ? lastInSequenceForEvent.getSequence() : 0) ); return gateway.add(addPayload); } @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); }
RunEntityService extends AbstractEntityService<
        Run,
        RunAddPayload,
        RunGateway> { @Override public Run add(RunAddPayload addPayload) throws AddEntityException { Run lastInSequenceForEvent = gateway.findLastInSequenceForEvent(addPayload.getEvent()); addPayload.setSequence( 1 + (lastInSequenceForEvent != null ? lastInSequenceForEvent.getSequence() : 0) ); return gateway.add(addPayload); } @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);  }