HourOfDayDetectionFilter implements DetectionFilter { @Override public void doFilter(DetectorRequest detectorRequest, DetectorResponse detectorResponse, DetectionFilterChain chain) { notNull(detectorRequest, "metricData can't be null"); if (metricTimeFallsWithinFilter(detectorRequest.getMetricData())) { chain.doFilter(detectorRequest, detectorResponse); } else { OutlierDetectorResult emptyResult = new OutlierDetectorResult(); detectorResponse.setDetectorResult(emptyResult); } } HourOfDayDetectionFilter(@JsonProperty("utcStartHour") int utcStartHour,
                                    @JsonProperty("utcEndHour") int utcEndHour); @Override void doFilter(DetectorRequest detectorRequest, DetectorResponse detectorResponse, DetectionFilterChain chain);  }
@Test public void testInsideFilteredPeriod() { when(mockDetector.detect(METRIC_DATA_INSIDE_NINE_TO_FIVE)).thenReturn(mockDetectorResult); DetectorResponse detectorResponse = new DetectorResponse(); filterUnderTest.doFilter(new DetectorRequest(METRIC_DATA_INSIDE_NINE_TO_FIVE), detectorResponse, chain()); DetectorResult actualResult = detectorResponse.getDetectorResult(); assertSame(mockDetectorResult, actualResult); }
@Test public void testOutsideFilteredPeriod() { DetectorResponse detectorResponse = new DetectorResponse(); filterUnderTest.doFilter(new DetectorRequest(METRIC_DATA_OUTSIDE_NINE_TO_FIVE), detectorResponse, chain()); OutlierDetectorResult emptyResult = new OutlierDetectorResult(); assertEquals(emptyResult, detectorResponse.getDetectorResult()); verify(mockDetector, never()).detect(any(MetricData.class)); }