### Question:
EnvClustersDeleteActions { @Bean(name = "DATAHUB_CLUSTERS_DELETE_STARTED_STATE") public Action<?, ?> datahubClustersDeleteAction() { return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) { @Override protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) { EnvironmentStatus environmentStatus = EnvironmentStatus.DATAHUB_CLUSTERS_DELETE_IN_PROGRESS; ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_DATAHUB_CLUSTERS_DELETION_STARTED; EnvClustersDeleteState envClustersDeleteState = EnvClustersDeleteState.DATAHUB_CLUSTERS_DELETE_STARTED_STATE; String logDeleteState = "Data Hub clusters"; EnvironmentDeletionDto envDto = commonUpdateEnvironmentAndNotify(context, payload, environmentStatus, resourceEvent, envClustersDeleteState, logDeleteState); sendEvent(context, DELETE_DATAHUB_CLUSTERS_EVENT.selector(), envDto); } }; } EnvClustersDeleteActions(EnvironmentService environmentService, EventSenderService eventService, EnvironmentMetricService metricService); @Bean(name = "DATAHUB_CLUSTERS_DELETE_STARTED_STATE") Action<?, ?> datahubClustersDeleteAction(); @Bean(name = "DATALAKE_CLUSTERS_DELETE_STARTED_STATE") Action<?, ?> datalakeClustersDeleteAction(); @Bean(name = "ENV_CLUSTERS_DELETE_FAILED_STATE") Action<?, ?> failedAction();  }### Answer:
@Test void datahubClustersDeleteActionFailure() { Action<?, ?> action = configureAction(() -> underTest.datahubClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenThrow(new UnsupportedOperationException(MESSAGE)); when(failureEvent.event()).thenReturn(FAILURE_EVENT); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(eventSenderService, never()).sendEventAndNotification(any(EnvironmentDto.class), anyString(), any(ResourceEvent.class)); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyFailureEvent(); }
@Test void datahubClustersDeleteActionNoEnvironment() { Action<?, ?> action = configureAction(() -> underTest.datahubClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.empty()); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environment, never()).setStatus(any()); verify(eventSenderService, never()).sendEventAndNotification(any(EnvironmentDto.class), anyString(), any(ResourceEvent.class)); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyDeleteActionSuccessEvent(DELETE_DATAHUB_CLUSTERS_EVENT); }
@Test void datahubClustersDeleteAction() { Action<?, ?> action = configureAction(() -> underTest.datahubClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment)); when(environmentService.save(environment)).thenReturn(savedEnvironment); when(environmentService.getEnvironmentDto(savedEnvironment)).thenReturn(environmentDto); action.execute(stateContext); verify(environment).setStatus(EnvironmentStatus.DATAHUB_CLUSTERS_DELETE_IN_PROGRESS); verify(eventSenderService).sendEventAndNotification(environmentDto, FLOW_TRIGGER_USER_CRN, ResourceEvent.ENVIRONMENT_DATAHUB_CLUSTERS_DELETION_STARTED); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyDeleteActionSuccessEvent(DELETE_DATAHUB_CLUSTERS_EVENT); }