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