DefaultDetectorSource implements DetectorSource { @Override public DetectorContainer findDetector(UUID uuid) { notNull(uuid, "uuid can't be null"); val document = client.findDetectorDocument(uuid); val detector = detectorFactory.buildDetector(document); if (detector == null) return null; val filters = DetectorDocumentParserUtil.parseFilters(document); return new DetectorContainer(detector, filters); }  @Override DetectorMatchResponse findDetectorMappings(List<Map<String, String>> metricTags); @Override List<DetectorMapping> findUpdatedDetectorMappings(long timePeriod); @Override DetectorMapping findDetectorMappingByUuid(UUID uuid); @Override DetectorContainer findDetector(UUID uuid); @Override List<UUID> findUpdatedDetectors(long timePeriod); @Override void updatedDetectorLastUsed(UUID uuid);  }
@Test public void testBuildDetectorContainer() { val result = sourceUnderTest.findDetector(DETECTOR_UUID); assertNotNull(result); }
@Test(expected = IllegalArgumentException.class) public void testFindDetector_nullMeta() { sourceUnderTest.findDetector(null); }
@Test public void testFindDetector_nullDetectorBuilt() { when(detectorClient.findDetectorDocument(DETECTOR_UUID)).thenReturn(detectorDocument); when(detectorFactory.buildDetector(detectorDocument)).thenReturn(null); DetectorContainer detector = sourceUnderTest.findDetector(DETECTOR_UUID); assertNull(detector); }
@Test(expected = DetectorException.class) public void testFindDetector_missingDetector() { sourceUnderTest.findDetector(DETECTOR_UUID_MISSING_DETECTOR); }
@Test(expected = RuntimeException.class) public void testFindDetector_exception() { sourceUnderTest.findDetector(DETECTOR_UUID_EXCEPTION); }