### Question:
StackOperationService { @VisibleForTesting FlowIdentifier start(Stack stack, Cluster cluster, boolean updateCluster, User user) { FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered(); environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.startable()); if (stack.isAvailable() && (cluster == null || cluster.isAvailable())) { eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), STACK_START_IGNORED); } else if (isStackStartable(stack) || isClusterStartable(cluster)) { Stack startStack = stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED); flowIdentifier = flowManager.triggerStackStart(stack.getId()); if (updateCluster && cluster != null) { clusterOperationService.updateStatus(startStack, StatusRequest.STARTED); } } else { throw NotAllowedStatusUpdate .stack(stack) .to(DetailedStackStatus.START_REQUESTED) .badRequest(); } return flowIdentifier; }  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 testStartWhenStackAvailable() { Stack stack = new Stack(); stack.setStackStatus(new StackStatus(stack, AVAILABLE)); stack.setId(1L); underTest.start(stack, null, false, new User()); verify(eventService, times(1)).fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), STACK_START_IGNORED); }
@Test public void testStartWhenStackStopped() { Stack stack = new Stack(); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.STOPPED)); stack.setId(1L); underTest.start(stack, null, false, new User()); verify(flowManager, times(1)).triggerStackStart(stack.getId()); verify(stackUpdater, times(1)).updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED); }
@Test public void testStartWhenStackStartFailed() { Stack stack = new Stack(); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.START_FAILED)); stack.setId(1L); underTest.start(stack, null, false, new User()); verify(flowManager, times(1)).triggerStackStart(stack.getId()); verify(stackUpdater, times(1)).updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED); }
@Test public void testStartWhenStackStopFailed() { Stack stack = new Stack(); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.STOP_FAILED)); stack.setId(1L); expectedException.expect(BadRequestException.class); expectedException.expectMessage(""); underTest.start(stack, null, false, new User()); verify(stackUpdater, times(1)).updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED); }
@Test public void testStartWhenClusterStopFailed() { Stack stack = new Stack(); stack.setId(9876L); stack.setStackStatus(new StackStatus(stack, AVAILABLE)); Cluster cluster = new Cluster(); cluster.setStatus(Status.STOPPED); stack.setCluster(cluster); underTest.start(stack, cluster, false, new User()); verify(flowManager, times(1)).triggerStackStart(stack.getId()); verify(stackUpdater, times(1)).updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED); }
@Test public void testStartWhenCheckCallEnvironmentCheck() { 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.start(stack, cluster, false, new User()); verify(environmentService).checkEnvironmentStatus(stack, EnvironmentStatus.startable()); }