SuspensionPostProcess { public void completeSuspensionSuccessfully(final List<SuspensionResult> successfulResults, final UUID commandId, final SuspensionCommand suspensionCommand) { final String suspensionCommandName = suspensionCommand.getName(); final List<String> suspendablesNames = suspensionResultsMapper.getSuspendablesNames(successfulResults); final String message = format( "%s completed successfully for %s", suspensionCommandName, suspendablesNames); systemCommandStateChangedEventFirer.fire(new SystemCommandStateChangedEvent( commandId, suspensionCommand, COMMAND_COMPLETE, clock.now(), message )); }  void completeSuspensionSuccessfully(final List<SuspensionResult> successfulResults, final UUID commandId, final SuspensionCommand suspensionCommand); void completeSuspensionWithFailures(final List<SuspensionResult> failureResults, final UUID commandId, final SuspensionCommand suspensionCommand);  }
@Test public void shouldFireCompletedEventIfSuspensionWasSuccessful() throws Exception { final UUID commandId = randomUUID(); final ZonedDateTime stateChangedAt = new UtcClock().now(); final SuspensionCommand suspensionCommand = new SuspendCommand(); final List<SuspensionResult> successfulResults = asList(mock(SuspensionResult.class), mock(SuspensionResult.class)); final List<String> suspendableNames = asList("Suspendable_1", "Suspendable_2"); when(suspensionResultsMapper.getSuspendablesNames(successfulResults)).thenReturn(suspendableNames); when(clock.now()).thenReturn(stateChangedAt); suspensionPostProcess.completeSuspensionSuccessfully(successfulResults, commandId, suspensionCommand); verify(systemCommandStateChangedEventFirer).fire(systemCommandStateChangedEventCaptor.capture()); final SystemCommandStateChangedEvent stateChangedEvent = systemCommandStateChangedEventCaptor.getValue(); assertThat(stateChangedEvent.getCommandId(), is(commandId)); assertThat(stateChangedEvent.getSystemCommand(), is(suspensionCommand)); assertThat(stateChangedEvent.getCommandState(), is(COMMAND_COMPLETE)); assertThat(stateChangedEvent.getStatusChangedAt(), is(stateChangedAt)); assertThat(stateChangedEvent.getMessage(), is("SUSPEND completed successfully for [Suspendable_1, Suspendable_2]")); }