LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public void deleteDetector(String uuid) { MDC.put("DetectorUuid", uuid); val deleteRequest = new DeleteRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid); try { val deleteResponse = legacyElasticSearchClient.delete(deleteRequest, RequestOptions.DEFAULT); if (elasticsearchUtil.checkNullResponse(deleteResponse.getResult())) { throw new RecordNotFoundException("Invalid request: " + uuid); } } catch (IOException e) { log.error("Deleting detector failed", e); throw new RuntimeException(e); } finally { MDC.remove("DetectorUuid"); } }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate);  }
@Test public void testDeleteDetector() { val detectorRepository = mock(LegacyDetectorRepository.class); doNothing().when(detectorRepository).deleteDetector(anyString()); detectorRepository.deleteDetector("aeb4d849-847a-45c0-8312-dc0fcf22b639"); verify(detectorRepository, times(1)).deleteDetector("aeb4d849-847a-45c0-8312-dc0fcf22b639"); }
@Test(expected = RuntimeException.class) public void deleteDetectorFail() throws IOException { Mockito.when(legacyElasticSearchClient.delete(any(DeleteRequest.class), any(RequestOptions.class))).thenThrow(new IOException()); repoUnderTest.deleteDetector("aeb4d849-847a-45c0-8312-dc0fcf22b639"); }
@Test(expected = RecordNotFoundException.class) public void deleteDetector_illegal_args() { Mockito.when(deleteResponse.getResult()).thenReturn(DocWriteResponse.Result.NOT_FOUND); Mockito.when(elasticsearchUtil.checkNullResponse(deleteResponse.getResult())).thenReturn(true); repoUnderTest.deleteDetector("aeb4d849-847a-45c0-8312-dc0fcf22b639"); }