AnomalyRepositoryImpl implements AnomalyRepository { @Override public List<OutlierDetectorResult> getAnomalies(AnomalyRequest request) { val metricDef = MetricUtil.metricDefinition(); val detector = buildDetector(request); val anomalyResults = new ArrayList<OutlierDetectorResult>(); metricSources.forEach(metricSource -> { val results = metricSource.getMetricData(request.getMetricTags()); for (val result : results) { val metricData = MetricUtil.metricData(metricDef, result.getDataPoint(), result.getEpochSecond()); val anomalyResult = (OutlierDetectorResult) detector.detect(metricData); anomalyResults.add(anomalyResult); } }); return anomalyResults; }  @Override List<OutlierDetectorResult> getAnomalies(AnomalyRequest request);  }
@Test public void testGetAnomalies() { val actualResults = serviceUnderTest.getAnomalies(anomalyRequest); assertNotNull(actualResults); assertEquals(1, actualResults.size()); verify(graphiteMetricSource, atMost(1)).getMetricData(anyString()); }