### Question:
EnvironmentStatusCheckerJob extends StatusCheckerJob { @VisibleForTesting void syncAnEnv(Environment environment) { try { ThreadBasedUserCrnProvider.doAs(environment.getCreator(), () -> { EnvironmentStatus status = environmentSyncService.getStatusByFreeipa(environment); if (environment.getStatus() != status) { if (!flowLogService.isOtherFlowRunning(environment.getId())) { updateIfEnabled(environment, status); } else { LOGGER.info("EnvironmentStatusCheckerJob wants to update the status but it's ignored because a flow started on: {}", environment.getName()); } } else { LOGGER.info("Environment status is the same ({}), the update is skipped", status); } }); } catch (Exception e) { LOGGER.info("Environment sync is failed for {}, error: {}", environment.getName(), e.getMessage(), e); } } EnvironmentStatusCheckerJob(EnvironmentService environmentService, FlowLogService flowLogService,
            EnvironmentSyncService environmentSyncService, EnvironmentStatusUpdateService environmentStatusUpdateService,
            EnvironmentJobService environmentJobService, AutoSyncConfig autoSyncConfig);   }### Answer:
@Test void testSyncAnEnvSameStatus() { Environment environment = new Environment(); environment.setId(1234L); environment.setStatus(AVAILABLE); when(environmentSyncService.getStatusByFreeipa(environment)).thenReturn(AVAILABLE); underTest.syncAnEnv(environment); verify(environmentStatusUpdateService, never()).updateEnvironmentStatusAndNotify(eq(environment), any(), any()); }
@Test void testSyncAnEnvDifferentStatusAndUpdateEnabled() { Environment environment = new Environment(); environment.setId(1234L); environment.setStatus(ENV_STOPPED); when(environmentSyncService.getStatusByFreeipa(environment)).thenReturn(AVAILABLE); when(autoSyncConfig.isUpdateStatus()).thenReturn(true); underTest.syncAnEnv(environment); verify(environmentStatusUpdateService).updateEnvironmentStatusAndNotify(environment, AVAILABLE, ENVIRONMENT_SYNC_FINISHED); }
@Test void testSyncAnEnvDifferentStatusAndUpdateDisabled() { Environment environment = new Environment(); environment.setId(1234L); environment.setStatus(ENV_STOPPED); when(environmentSyncService.getStatusByFreeipa(environment)).thenReturn(AVAILABLE); when(autoSyncConfig.isUpdateStatus()).thenReturn(false); underTest.syncAnEnv(environment); verify(autoSyncConfig).isUpdateStatus(); verify(environmentStatusUpdateService, never()).updateEnvironmentStatusAndNotify(environment, AVAILABLE, ENVIRONMENT_SYNC_FINISHED); }