### Question:
TelemetryAgentService { public void stopTelemetryAgent(Long stackId) { stopTelemetryAgent(stackId, null); } TelemetryAgentService(TelemetryOrchestrator telemetryOrchestrator, GatewayConfigService gatewayConfigService,
            StackRepository stackRepository, InstanceMetaDataRepository instanceMetaDataRepository); void stopTelemetryAgent(Long stackId); void stopTelemetryAgent(Long stackId, List<String> instanceIds);  }### Answer:
@Test public void testStopTelemetryAgent() throws Exception { given(stackRepository.findById(1L)).willReturn(Optional.of(createStack())); given(instanceMetaDataRepository.findNotTerminatedForStack(1L)).willReturn(createInstanceMetadataSet()); doNothing().when(telemetryOrchestrator).stopTelemetryAgent(anyList(), anySet(), any(ExitCriteriaModel.class)); underTest.stopTelemetryAgent(1L); verify(telemetryOrchestrator, times(1)).stopTelemetryAgent(anyList(), anySet(), any(ExitCriteriaModel.class)); }
@Test public void testStopTelemetryAgentThrowsException() throws Exception { given(stackRepository.findById(1L)).willReturn(Optional.of(createStack())); given(instanceMetaDataRepository.findNotTerminatedForStack(1L)).willReturn(createInstanceMetadataSet()); doThrow(new CloudbreakOrchestratorFailedException("error")).when(telemetryOrchestrator) .stopTelemetryAgent(anyList(), anySet(), any(ExitCriteriaModel.class)); underTest.stopTelemetryAgent(1L); verify(stackRepository, times(1)).findById(1L); }