### Question:
EnvironmentStatusUpdateService { public EnvironmentDto updateEnvironmentStatusAndNotify(CommonContext context, Payload payload, EnvironmentStatus environmentStatus, ResourceEvent resourceEvent, Enum envState) { LOGGER.info("Flow entered into {}", envState.name()); return environmentService .findEnvironmentById(payload.getResourceId()) .map(environment -> { environment.setStatus(environmentStatus); Environment env = environmentService.save(environment); EnvironmentDto environmentDto = environmentService.getEnvironmentDto(env); eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), resourceEvent); return environmentDto; }).orElseThrow(() -> new IllegalStateException( String.format("Cannot update status of environment, because it does not exist: %s. ", payload.getResourceId()) )); } EnvironmentStatusUpdateService(EnvironmentService environmentService,
            EventSenderService eventService); EnvironmentDto updateEnvironmentStatusAndNotify(CommonContext context, Payload payload, EnvironmentStatus environmentStatus,
            ResourceEvent resourceEvent, Enum envState); EnvironmentDto updateFailedEnvironmentStatusAndNotify(CommonContext context, BaseFailedFlowEvent failedFlowEvent,
            EnvironmentStatus environmentStatus, ResourceEvent resourceEvent, Enum envState); void updateEnvironmentStatusAndNotify(Environment environment, EnvironmentStatus environmentStatus, ResourceEvent resourceEvent);  }### Answer:
@Test public void testUpdateEnvironmentStatusAndNotify() { CommonContext commonContext = new CommonContext(new FlowParameters("flowId", "userCrn", null)); EnvironmentDto environmentDto = EnvironmentDto.builder().withId(1L).withEnvironmentStatus(EnvironmentStatus.STOP_DATAHUB_FAILED).build(); Environment environment = new Environment(); when(environmentService.findEnvironmentById(environmentDto.getResourceId())).thenReturn(Optional.of(environment)); when(environmentService.save(environment)).thenReturn(environment); when(environmentService.getEnvironmentDto(environment)).thenReturn(environmentDto); EnvironmentDto actual = underTest.updateEnvironmentStatusAndNotify(commonContext, environmentDto, EnvironmentStatus.STOP_DATAHUB_FAILED, ResourceEvent.ENVIRONMENT_VALIDATION_FAILED, EnvStartState.ENV_START_FINISHED_STATE); Assertions.assertEquals(EnvironmentStatus.STOP_DATAHUB_FAILED, actual.getStatus()); verify(eventSenderService).sendEventAndNotification(environmentDto, "userCrn", ResourceEvent.ENVIRONMENT_VALIDATION_FAILED); }