### Question:
RedbeamsStopService { public void stopDatabaseServer(String crn) { DBStack dbStack = dbStackService.getByCrn(crn); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Stop called for: {}", dbStack); } if (dbStack.getStatus().isStopInProgressOrCompleted()) { LOGGER.debug("DatabaseServer with crn {} is already being stopped", dbStack.getResourceCrn()); return; } dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.STOP_REQUESTED); flowManager.notify(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), new RedbeamsEvent(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), dbStack.getId())); }  void stopDatabaseServer(String crn);  }### Answer:
@Test public void shouldSetStopRequestedStatusAndNotifyTheFlowManager() { when(dbStack.getId()).thenReturn(1L); when(dbStack.getStatus()).thenReturn(Status.AVAILABLE); Optional<DBStack> dbStackOptional = Optional.of(dbStack); when(dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.STOP_REQUESTED)).thenReturn(dbStackOptional); ArgumentCaptor<RedbeamsEvent> redbeamsEventArgumentCaptor = ArgumentCaptor.forClass(RedbeamsEvent.class); victim.stopDatabaseServer(CRN_STRING); verify(flowManager).notify(eq(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector()), redbeamsEventArgumentCaptor.capture()); assertEquals(dbStack.getId(), redbeamsEventArgumentCaptor.getValue().getResourceId()); assertEquals(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), redbeamsEventArgumentCaptor.getValue().selector()); }
@Test public void shouldReturnWithoutAnyActionWhenStopInProgress() { when(dbStack.getStatus()).thenReturn(Status.STOP_IN_PROGRESS); victim.stopDatabaseServer(CRN_STRING); verifyZeroInteractions(dbStackStatusUpdater, flowManager); }