### Question:
CaptureFilter implements Filter { @Override public Promise<Response, NeverThrowsException> filter(final Context context, final Request request, final Handler next) { if (points.contains(REQUEST)) { capture.capture(context, request, REQUEST); } return delegate.filter(context, request, new Handler() { @Override public Promise<Response, NeverThrowsException> handle(final Context context, final Request request) { if (points.contains(FILTERED_REQUEST)) { capture.capture(context, request, FILTERED_REQUEST); } return next.handle(context, request) .thenOnResult(new ResultHandler<Response>() { @Override public void handleResult(final Response response) { if (points.contains(RESPONSE)) { capture.capture(context, response, RESPONSE); } } }); } }).thenOnResult(new ResultHandler<Response>() { @Override public void handleResult(final Response response) { if (points.contains(FILTERED_RESPONSE)) { capture.capture(context, response, FILTERED_RESPONSE); } } }); } CaptureFilter(final Filter delegate, final MessageCapture capture, final Set<CapturePoint> points); @Override Promise<Response, NeverThrowsException> filter(final Context context,
                                                          final Request request,
                                                          final Handler next);  }### Answer:
@Test(dataProvider = "capturePointSets") public void shouldCaptureAllMessages(List<CapturePoint> points) throws Exception { CaptureFilter filter = new CaptureFilter(delegate, capture, new TreeSet<>(points)); Context context = new RootContext(); filter.filter(context, null, terminal).get(); for (CapturePoint capturePoint : points) { switch (capturePoint) { case REQUEST: case FILTERED_REQUEST: verify(capture).capture(context, (Request) null, capturePoint); break; case RESPONSE: case FILTERED_RESPONSE: verify(capture).capture(context, response, capturePoint); break; } } verifyNoMoreInteractions(capture); }