### Question:
CrestAuditor { void auditAccessFailure(int resultCode, String message) { if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) { final long endTime = System.currentTimeMillis(); final long elapsedTime = endTime - startTime; JsonValue detail = json(object(field(ACCESS_RESPONSE_DETAIL_REASON, message))); AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm) .forHttpRequest(context, request) .timestamp(endTime) .transactionId(AuditRequestContext.getTransactionIdValue()) .eventName(EventName.AM_ACCESS_OUTCOME) .component(component) .responseWithDetail(FAILED, Integer.toString(resultCode), elapsedTime, MILLISECONDS, detail); addSessionDetailsFromSSOTokenContext(builder, context); if (ipAddressHeaderPropertyIsSet()) { setClientFromHttpContextHeaderIfExists(builder, context); } AuditEvent auditEvent = builder.toEvent(); postProcessEvent(auditEvent); auditEventPublisher.tryPublish(ACCESS_TOPIC, auditEvent); } } CrestAuditor(Debug debug, AuditEventPublisher auditEventPublisher,
                 AuditEventFactory auditEventFactory, Context context, Request request);   }### Answer:
@Test(dataProvider = "CRESTRequests") public void auditFailureShouldPublishEvents(Request request) throws Exception { given(auditEventPublisher.isAuditing(anyString(), anyString(), any(EventName.class))).willReturn(true); auditor = new CrestAuditor(debug, auditEventPublisher, auditEventFactory, context, request); givenAccessAuditingEnabled(auditEventPublisher); auditor.auditAccessFailure(500, "my bad"); ArgumentCaptor<AuditEvent> auditEventCaptor = ArgumentCaptor.forClass(AuditEvent.class); verify(auditEventPublisher).tryPublish(eq(ACCESS_TOPIC), auditEventCaptor.capture()); assertThat(getField(auditEventCaptor, EVENT_NAME).asString()).isEqualTo(EventName.AM_ACCESS_OUTCOME.toString()); assertThat(getField(auditEventCaptor, RESPONSE + "/" + STATUS_CODE).asString()).isEqualTo("500"); assertThat(getField(auditEventCaptor, RESPONSE + "/" + DETAIL + "/" + ACCESS_RESPONSE_DETAIL_REASON).asString()) .isEqualTo("my bad"); }