### Question:
SynchronizeUsersHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { LOGGER.debug("User synchronization is {}.", synchronizeOnStartEnabled ? "enabled" : "disabled"); EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { if (synchronizeOnStartEnabled) { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isAvailable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in AVAILABLE state to synchronize users! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.waitForSynchronizeUsers(environmentDto.getId(), environmentDto.getResourceCrn()); } EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent() .withSelector(EnvStartStateSelectors.FINISH_ENV_START_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStartEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_SYNCHRONIZE_USERS_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  SynchronizeUsersHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); @Override String selector(); @Override void accept(Event<EnvironmentDto> environmentDtoEvent);  }### Answer:
@Test void testWhenFreeIpaIsNotAvailableThenFail() { ReflectionTestUtils.setField(underTest, "synchronizeOnStartEnabled", true); when(freeIpaService.describe(ENV_CRN)).thenReturn(Optional.of(describeFreeIpaResponse)); when(describeFreeIpaResponse.getStatus()).thenReturn(Status.STOPPED); underTest.accept(environmentDtoEvent); verify(eventSender, never()).sendEvent(any(EnvStartEvent.class), eq(eventHeaders)); verify(freeIpaPollerService, never()).waitForSynchronizeUsers(any(), any()); ArgumentCaptor<EnvStartFailedEvent> failEventCaptor = ArgumentCaptor.forClass(EnvStartFailedEvent.class); verify(eventSender, times(1)).sendEvent(failEventCaptor.capture(), eq(eventHeaders)); EnvStartFailedEvent failedEvent = failEventCaptor.getValue(); assertThat(failedEvent.getEnvironmentStatus()).isEqualTo(EnvironmentStatus.START_SYNCHRONIZE_USERS_FAILED); }