### Question:
HealthCheckEventLogger { public void logException(ApplicationException exception, String message) { LOG.warn(message, exception); if (exception.isAudited() || !exception.requiresAuditing()) { return; } Map<EventDetailsKey, String> details = Map.of( downstream_uri, exception.getUri().orElse(URI.create("uri-not-present")).toASCIIString(), EventDetailsKey.message, exception.getMessage()); EventSinkHubEvent hubEvent = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT, details); eventSinkProxy.logHubEvent(hubEvent); eventEmitter.record(hubEvent); } @Inject  HealthCheckEventLogger(EventSinkProxy eventSinkProxy,
                                  EventEmitter eventEmitter,
                                  ServiceInfoConfiguration serviceInfo); void logException(ApplicationException exception, String message);  }### Answer:
@Test public void shouldLogToEventSinkIfTheExceptionIsUnaudited() { URI uri = URI.create("uri-geller"); ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID(), uri); Map<EventDetailsKey, String> details = Map.of( downstream_uri, unauditedException.getUri().orElse(URI.create("uri-not-present")).toASCIIString(), message, unauditedException.getMessage()); EventSinkHubEvent event = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT,details); eventLogger.logException(unauditedException, "test error message"); ArgumentCaptor<EventSinkHubEvent> eventSinkCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class); ArgumentCaptor<EventSinkHubEvent> eventEmitterCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class); verify(eventSinkProxy, times(1)).logHubEvent(eventSinkCaptor.capture()); verify(eventEmitter, times(1)).record(eventEmitterCaptor.capture()); assertThat(event).isEqualToComparingOnlyGivenFields(eventSinkCaptor.getValue(), "originatingService", "sessionId", "eventType", "details"); assertThat(event).isEqualToComparingOnlyGivenFields(eventEmitterCaptor.getValue(), "originatingService", "sessionId", "eventType", "details"); }
@Test public void shouldNotLogToEventSinkIfTheExceptionIsAudited() { ApplicationException unauditedException = ApplicationException.createAuditedException(ExceptionType.INVALID_SAML, UUID.randomUUID()); eventLogger.logException(unauditedException, "test error message"); verify(eventSinkProxy, times(0)).logHubEvent(any()); }
@Test public void shouldNotLogToEventSinkIfTheExceptionIsUnauditedButShouldNotBeaudited() { ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID()); eventLogger.logException(unauditedException, "test error message"); verify(eventSinkProxy, times(0)).logHubEvent(any()); }