### Question:
AbstractHttpAccessAuditFilter implements Filter { @Override public Promise<Response, NeverThrowsException> filter(final Context context, final Request request, Handler next) { auditAccessAttempt(request, context); return next.handle(context, request).then(new Function<Response, Response, NeverThrowsException>() { @Override public Response apply(Response response) { if (response.getStatus().isSuccessful()) { auditAccessSuccess(request, context, response); } else { auditAccessFailure(request, context, response); } return response; } }); } AbstractHttpAccessAuditFilter(Component component,
            AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory); @Override Promise<Response, NeverThrowsException> filter(final Context context, final Request request, Handler next);  }### Answer:
@Test(dataProvider = "handlerResponses") public void shouldNotAuditIfAuditingIsNotEnabledForAccessTopic(Status responseStatus) throws AuditException { Context context = new RequestAuditContext(mockContext()); Request request = new Request() .setUri(URI.create("http: disableAccessTopicAuditing(); Handler handler = mockHandler(context, request, responseStatus); auditFilter.filter(context, request, handler); verify(eventPublisher, never()).tryPublish(anyString(), any(AuditEvent.class)); }
@Test(dataProvider = "handlerResponses") public void shouldAuditAccessAttemptAndResult(Status responseStatus) throws AuditException { Context context = new RequestAuditContext(mockContext()); Request request = new Request() .setMethod("GET") .setUri(URI.create("http: request.getHeaders().put(ContentTypeHeader.valueOf("CONTENT_TYPE")); enableAccessTopicAuditing(); Handler handler = mockHandler(context, request, responseStatus); auditFilter.filter(context, request, handler); ArgumentCaptor<AuditEvent> auditEventCaptor = ArgumentCaptor.forClass(AuditEvent.class); verify(eventPublisher, times(2)).tryPublish(eq(AuditConstants.ACCESS_TOPIC), auditEventCaptor.capture()); verifyAccessAttemptAuditEvent(auditEventCaptor.getAllValues().get(0).getValue()); if (responseStatus.isSuccessful()) { verifyAccessSuccessAuditEvent(auditEventCaptor.getAllValues().get(1).getValue()); } else { verifyAccessFailedAuditEvent(auditEventCaptor.getAllValues().get(1).getValue()); } }