### Question:
CollectDownscaleCandidatesHandler implements EventHandler<CollectDownscaleCandidatesRequest> { @Override public void accept(Event<CollectDownscaleCandidatesRequest> event) { CollectDownscaleCandidatesRequest request = event.getData(); CollectDownscaleCandidatesResult result; try { result = transactionService.required(() -> { try { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); int defaultRootVolumeSize = defaultRootVolumeSizeProvider.getForPlatform(stack.cloudPlatform()); Set<Long> privateIds = request.getPrivateIds(); if (noSelectedInstancesForDownscale(privateIds)) { privateIds = collectCandidates(request, stack, defaultRootVolumeSize); } else { List<InstanceMetaData> removableInstances = stackService.getInstanceMetaDataForPrivateIdsWithoutTerminatedInstances(stack.getInstanceMetaDataAsList(), privateIds); List<InstanceMetaData> removableAndNotDeletedInstances = removableInstances.stream() .filter(instanceMetaData -> !instanceMetaData.isTerminated() && !instanceMetaData.isDeletedOnProvider()) .collect(Collectors.toList()); if (!request.getDetails().isForced()) { clusterApiConnectors.getConnector(stack).clusterDecomissionService() .verifyNodesAreRemovable(stack, removableAndNotDeletedInstances); } } return new CollectDownscaleCandidatesResult(request, privateIds); } catch (Exception e) { return new CollectDownscaleCandidatesResult(e.getMessage(), e, request); } }); } catch (TransactionExecutionException e) { throw e.getCause(); } eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }  @Override String selector(); @Override void accept(Event<CollectDownscaleCandidatesRequest> event);  }### Answer:
@Test public void testFlowWithPrivateIds() { Stack stack = generateStackData(); when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack); Event<CollectDownscaleCandidatesRequest> event = generateTestDataEvent(Collections.singleton(PRIVATE_ID)); testedClass.accept(event); ArgumentCaptor<Event<CollectDownscaleCandidatesResult>> capturedEvent = ArgumentCaptor.forClass(Event.class); verify(eventBus).notify((Object) any(), capturedEvent.capture()); Event<CollectDownscaleCandidatesResult> submittedEvent = capturedEvent.getValue(); CollectDownscaleCandidatesResult submittedResult = submittedEvent.getData(); assertNotNull(submittedResult); }
@Test public void downScaleNotForced() { Stack stack = generateStackData(); Event<CollectDownscaleCandidatesRequest> event = generateTestDataEvent(Collections.singleton(PRIVATE_ID)); when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack); testedClass.accept(event); ArgumentCaptor<Event<CollectDownscaleCandidatesResult>> capturedEvent = ArgumentCaptor.forClass(Event.class); verify(eventBus).notify((Object) any(), capturedEvent.capture()); Event<CollectDownscaleCandidatesResult> submittedEvent = capturedEvent.getValue(); CollectDownscaleCandidatesResult submittedResult = submittedEvent.getData(); assertNotNull(submittedResult); assertFalse(submittedResult.getRequest().getDetails().isForced()); }
@Test public void downScaleForcedForced() { Stack stack = generateStackData(); Event<CollectDownscaleCandidatesRequest> event = generateTestDataEvent(Collections.singleton(PRIVATE_ID), new ClusterDownscaleDetails(true, false)); when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack); testedClass.accept(event); ArgumentCaptor<Event<CollectDownscaleCandidatesResult>> capturedEvent = ArgumentCaptor.forClass(Event.class); verify(eventBus).notify((Object) any(), capturedEvent.capture()); Event<CollectDownscaleCandidatesResult> submittedEvent = capturedEvent.getValue(); CollectDownscaleCandidatesResult submittedResult = submittedEvent.getData(); assertNotNull(submittedResult); assertTrue(submittedResult.getRequest().getDetails().isForced()); }