### Question:
StackStatusCheckerJob extends StatusCheckerJob { @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { if (flowLogService.isOtherFlowRunning(getStackId())) { LOGGER.debug("StackStatusCheckerJob cannot run, because flow is running for stack: {}", getStackId()); return; } try { Stack stack = stackService.get(getStackId()); buildMdcContext(stack); if (unshedulableStates().contains(stack.getStatus())) { LOGGER.debug("Stack sync will be unscheduled, stack state is {}", stack.getStatus()); jobService.unschedule(getLocalId()); } else if (null == stack.getStatus() || ignoredStates().contains(stack.getStatus())) { LOGGER.debug("Stack sync is skipped, stack state is {}", stack.getStatus()); } else if (syncableStates().contains(stack.getStatus())) { ThreadBasedUserCrnProvider.doAs(DATAHUB_INTERNAL_ACTOR_CRN, () -> doSync(stack)); } else { LOGGER.warn("Unhandled stack status, {}", stack.getStatus()); } } catch (Exception e) { LOGGER.info("Exception during cluster state check.", e); } finally { MDCBuilder.cleanupMdc(); } }    }### Answer:
@Test public void testNotRunningIfFlowInProgress() throws JobExecutionException { when(flowLogService.isOtherFlowRunning(anyLong())).thenReturn(Boolean.TRUE); underTest.executeInternal(jobExecutionContext); verify(stackService, times(0)).getByIdWithListsInTransaction(anyLong()); }
@Test public void testNotRunningIfStackFailedOrBeingDeleted() throws JobExecutionException { setStackStatus(DetailedStackStatus.DELETE_COMPLETED); underTest.executeInternal(jobExecutionContext); verify(clusterApiConnectors, times(0)).getConnector(stack); }
@Test public void testInstanceSyncIfCMNotAccessible() throws JobExecutionException { setupForCMNotAccessible(); underTest.executeInternal(jobExecutionContext); verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any()); }
@Test public void testInstanceSyncCMNotRunning() throws JobExecutionException { setupForCM(); underTest.executeInternal(jobExecutionContext); verify(clusterOperationService, times(0)).reportHealthChange(anyString(), anySet(), anySet()); verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any()); }
@Test public void testInstanceSyncCMRunning() throws JobExecutionException { setupForCM(); when(clusterStatusResult.getClusterStatus()).thenReturn(ClusterStatus.CLUSTERMANAGER_RUNNING); when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi); when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService); underTest.executeInternal(jobExecutionContext); verify(clusterOperationService, times(1)).reportHealthChange(any(), anySet(), anySet()); verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any()); verify(clusterService, times(1)).updateClusterCertExpirationState(stack.getCluster(), true); }