### Question:
StackOperationService { public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user) { Stack stack = stackService.getByIdWithLists(stackId); Cluster cluster = null; if (stack.getCluster() != null) { cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null); } switch (status) { case SYNC: return sync(stack, false, user); case FULL_SYNC: return sync(stack, true, user); case REPAIR_FAILED_NODES: return repairFailedNodes(stack, user); case STOPPED: return stop(stack, cluster, updateCluster, user); case STARTED: return start(stack, cluster, updateCluster, user); default: throw new BadRequestException("Cannot update the status of stack because status request not valid."); } }  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 shouldNotTriggerStopWhenStackRunsOnSpotInstances() { Stack stack = new Stack(); stack.setId(9876L); stack.setStackStatus(new StackStatus(stack, AVAILABLE)); stack.setInstanceGroups(Set.of(createInstanceGroup(100))); when(stackService.getByIdWithLists(stack.getId())).thenReturn(stack); Assertions.assertThatThrownBy(() -> underTest.updateStatus(stack.getId(), StatusRequest.STOPPED, true, new User())) .isInstanceOf(BadRequestException.class) .hasMessage(String.format("Cannot update the status of stack '%s' to STOPPED, because it runs on spot instances", stack.getName())); verify(stackUpdater, never()).updateStackStatus(any(), any()); }
@Test public void shouldTriggerStopWhenStackRunsOnOnDemandInstances() { Stack stack = new Stack(); stack.setId(9876L); stack.setStackStatus(new StackStatus(stack, AVAILABLE)); stack.setInstanceGroups(Set.of(createInstanceGroup(0), createInstanceGroup(null))); when(stackService.getByIdWithLists(stack.getId())).thenReturn(stack); underTest.updateStatus(stack.getId(), StatusRequest.STOPPED, true, new User()); verify(stackUpdater).updateStackStatus(stack.getId(), STOP_REQUESTED); }