### Question:
StopDatabaseServerFailedAction extends AbstractRedbeamsStopAction<RedbeamsFailureEvent> { @Override protected void prepareExecution(RedbeamsFailureEvent payload, Map<Object, Object> variables) { Exception failureException = payload.getException(); LOGGER.info("Error during database server stop flow:", failureException); String errorReason = failureException == null ? "Unknown error" : failureException.getMessage(); Optional<DBStack> dbStack = dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.STOP_FAILED, errorReason); metricService.incrementMetricCounter(MetricType.DB_STOP_FAILED, dbStack); } StopDatabaseServerFailedAction();   }### Answer:
@Test public void shouldUpdateStatusAndIncrementMetricOnPrepare() { RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, exception); Optional<DBStack> dbStackOptional = Optional.of(dbStack); when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOP_FAILED, null)).thenReturn(dbStackOptional); victim.prepareExecution(event, null); verify(metricService).incrementMetricCounter(MetricType.DB_STOP_FAILED, dbStackOptional); }
@Test public void shouldUpdateStatusWithUknownErrorAndIncrementMetricOnPrepare() { RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, null); Optional<DBStack> dbStackOptional = Optional.of(dbStack); when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOP_FAILED, "Unknown error")).thenReturn(Optional.of(dbStack)); victim.prepareExecution(event, null); verify(metricService).incrementMetricCounter(MetricType.DB_STOP_FAILED, dbStackOptional); }