### Question:
AuditFilter extends AuditBaseObject implements Filter { @Override public Promise<Response, NeverThrowsException> filter(final Context context, final Request request, final Handler next) { fireAuditEvent(bindings(context, request), requestTags); return delegate.filter(context, request, next) .thenOnResult(new ResultHandler<Response>() { @Override public void handleResult(final Response response) { fireAuditEvent(bindings(context, request, response), completedResponseTags); } }); } AuditFilter(final org.forgerock.openig.audit.AuditSystem auditSystem,
                       final org.forgerock.openig.audit.AuditSource source,
                       final Filter delegate,
                       final Set<String> additionalTags); @Override Promise<Response, NeverThrowsException> filter(final Context context,
                                                          final Request request,
                                                          final Handler next);  }### Answer:
@Test(dataProvider = "nullOrEmpty") public void shouldEmitAuditEventsWithAdditionalTagsContainingNullOrEmpty(final Set<String> additionalTags) throws Exception { AuditFilter audit = new AuditFilter(auditSystem, source, delegate, additionalTags); Context context = new RootContext(); when(delegate.filter(context, null, handler)) .thenReturn(Promises.<Response, NeverThrowsException>newResultPromise(new Response())); audit.filter(context, null, handler).getOrThrow(); verify(auditSystem, times(2)).onAuditEvent(captor.capture()); assertThatEventIncludes(captor.getAllValues().get(0), context, "request"); assertThatEventIncludes(captor.getAllValues().get(1), context, "response", "completed"); }
@Test public void shouldEmitAuditEventsWhenCompleted() throws Exception { AuditFilter audit = new AuditFilter(auditSystem, source, delegate, singleton("tag")); Context context = new RootContext(); when(delegate.filter(context, null, handler)) .thenReturn(Promises.<Response, NeverThrowsException>newResultPromise(new Response())); audit.filter(context, null, handler).getOrThrow(); verify(auditSystem, times(2)).onAuditEvent(captor.capture()); assertThatEventIncludes(captor.getAllValues().get(0), context, "tag", "request"); assertThatEventIncludes(captor.getAllValues().get(1), context, "tag", "response", "completed"); }