### Question:
StackOperationService { @VisibleForTesting FlowIdentifier triggerStackStopIfNeeded(Stack stack, Cluster cluster, boolean updateCluster, User user) { if (!isStopNeeded(stack)) { return FlowIdentifier.notTriggered(); } if (isStackRunsOnSpotInstances(stack)) { throw new BadRequestException(format("Cannot update the status of stack '%s' to STOPPED, because it runs on spot instances", stack.getName())); } environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.stoppable()); if (cluster != null && !cluster.isStopped() && !stack.isStopFailed()) { if (!updateCluster) { throw NotAllowedStatusUpdate .stack(stack) .to(STOPPED) .badRequest(); } else if (cluster.isClusterReadyForStop() || cluster.isStopFailed()) { setStackStatusToStopRequested(stack); return clusterOperationService.updateStatus(stack.getId(), StatusRequest.STOPPED); } else { throw NotAllowedStatusUpdate .cluster(stack) .to(STOPPED) .badRequest(); } } else { stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STOP_REQUESTED); return flowManager.triggerStackStop(stack.getId()); } }  FlowIdentifier removeInstance(Stack stack, Long workspaceId, String instanceId, boolean forced, User user); FlowIdentifier removeInstances(Stack stack, Long workspaceId, Collection<String> instanceIds, boolean forced, User user); FlowIdentifier updateImage(Long stackId, Long workspaceId, String imageId, String imageCatalogName, String imageCatalogUrl, User user); FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user); FlowIdentifier updateNodeCount(Stack stack, InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson, boolean withClusterEvent, User user); void renewCertificate(String stackName);  }### Answer:
@Test public void testTriggerStackStopIfNeededWhenCheckCallEnvironmentCheck() { Stack stack = new Stack(); stack.setId(9876L); stack.setStackStatus(new StackStatus(stack, AVAILABLE)); Cluster cluster = new Cluster(); stack.setCluster(cluster); cluster.setStatus(Status.STOPPED); underTest.triggerStackStopIfNeeded(stack, cluster, false, new User()); verify(environmentService).checkEnvironmentStatus(stack, EnvironmentStatus.stoppable()); }