DetectionFilterChain { public void doFilter(@NonNull DetectorRequest request, @NonNull DetectorResponse response) { if (!filtersIterator.hasNext()) { val result = detector.detect(request.getMetricData()); response.setDetectorResult(result); } else { DetectionFilter f = filtersIterator.next(); f.doFilter(request, response, this); } } DetectionFilterChain(DetectorContainer detectorContainer); void doFilter(@NonNull DetectorRequest request, @NonNull DetectorResponse response);  }
@Test public void doFilterWithEmptyChain() { when(detectorContainer.getDetector()).thenReturn(detector); when(detectorRequest.getMetricData()).thenReturn(metricData); chainUnderTest = new DetectionFilterChain(detectorContainer); chainUnderTest.doFilter(detectorRequest, detectorResponse); }
@Test public void doFilterWithChain_ensureChainKeepsResultFromFilter() { DetectionFilter stubDetectionFilter = (detectorRequest, detectorResponse, chain) -> detectorResponse.setDetectorResult(detectorResult); DetectorContainer detectorContainer = new DetectorContainer(detector, ImmutableList.of(stubDetectionFilter)); chainUnderTest = new DetectionFilterChain(detectorContainer); DetectorResponse actualDetectorResponse = new DetectorResponse(); chainUnderTest.doFilter(detectorRequest, actualDetectorResponse); assertSame(detectorResult, actualDetectorResponse.getDetectorResult()); }
@Test(expected = NullPointerException.class) public void nullDetectorRequestNotAllowed() { chainUnderTest.doFilter(null, detectorResponse); }
@Test(expected = NullPointerException.class) public void nullDetectorResponseNotAllowed() { chainUnderTest.doFilter(detectorRequest, null); }