### Question:
TelemetryAgentService { public void stopTelemetryAgent(Stack stack) { try { Set<InstanceMetaData> instanceMetaDataSet = stack.getNotDeletedInstanceMetaDataSet(); List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack); Set<Node> allNodes = instanceMetaDataSet.stream() .map(im -> new Node(im.getPrivateIp(), im.getPublicIp(), im.getInstanceId(), im.getInstanceGroup().getTemplate().getInstanceType(), im.getDiscoveryFQDN(), im.getInstanceGroup().getGroupName())) .collect(Collectors.toSet()); telemetryOrchestrator.stopTelemetryAgent(gatewayConfigs, allNodes, ClusterDeletionBasedExitCriteriaModel.nonCancellableModel()); } catch (CloudbreakOrchestratorFailedException e) { LOGGER.warn("Non-critical error during stopping telemetry agent", e); } catch (Exception e) { LOGGER.error("Error during stopping telemetry agent", e); } } TelemetryAgentService(TelemetryOrchestrator telemetryOrchestrator, GatewayConfigService gatewayConfigService); void stopTelemetryAgent(Stack stack);  }### Answer:
@Test public void testStopTelemetryAgent() throws Exception { doNothing().when(telemetryOrchestrator).stopTelemetryAgent(anyList(), anySet(), any(ExitCriteriaModel.class)); underTest.stopTelemetryAgent(createStack()); verify(telemetryOrchestrator, times(1)).stopTelemetryAgent(anyList(), anySet(), any(ExitCriteriaModel.class)); }
@Test public void testStopTelemetryAgentThrowsException() throws Exception { given(gatewayConfigService.getAllGatewayConfigs(any(Stack.class))).willReturn(null); doThrow(new CloudbreakOrchestratorFailedException("error")).when(telemetryOrchestrator) .stopTelemetryAgent(anyList(), anySet(), any(ExitCriteriaModel.class)); underTest.stopTelemetryAgent(createStack()); verify(gatewayConfigService, times(1)).getAllGatewayConfigs(any(Stack.class)); }