SpanCustomizingApplicationEventListener implements ApplicationEventListener, RequestEventListener { @Override public void onEvent(ApplicationEvent event) { } @Inject  SpanCustomizingApplicationEventListener(EventParser parser); static SpanCustomizingApplicationEventListener create(); static SpanCustomizingApplicationEventListener create(EventParser parser); @Override void onEvent(ApplicationEvent event); @Override RequestEventListener onRequest(RequestEvent requestEvent); @Override void onEvent(RequestEvent event);  }
@Test public void onEvent_processesFINISHED() { setEventType(RequestEvent.Type.FINISHED); setBaseUri("/"); when(request.getProperty(SpanCustomizer.class.getName())).thenReturn(span); listener.onEvent(requestEvent); verify(parser).requestMatched(requestEvent, span); }
@Test public void onEvent_setsErrorWhenNotAlreadySet() { setEventType(RequestEvent.Type.FINISHED); setBaseUri("/"); when(request.getProperty(SpanCustomizer.class.getName())).thenReturn(span); Exception error = new Exception(); when(requestEvent.getException()).thenReturn(error); when(request.getProperty("error")).thenReturn(null); listener.onEvent(requestEvent); verify(request).setProperty("error", error); }
@Test public void onEvent_skipsErrorWhenSet() { setEventType(RequestEvent.Type.FINISHED); setBaseUri("/"); when(request.getProperty(SpanCustomizer.class.getName())).thenReturn(span); Exception error = new Exception(); when(requestEvent.getException()).thenReturn(error); when(request.getProperty("error")).thenReturn("madness"); listener.onEvent(requestEvent); verify(request).getProperty(SpanCustomizer.class.getName()); verify(request).getProperty("error"); verify(request).getUriInfo(); verify(request).setProperty("http.route", ""); verifyNoMoreInteractions(request); }
@Test public void onEvent_toleratesMissingCustomizer() { setEventType(RequestEvent.Type.FINISHED); setBaseUri("/"); listener.onEvent(requestEvent); verifyNoMoreInteractions(parser); }
@Test public void onEvent_toleratesBadCustomizer() { setEventType(RequestEvent.Type.FINISHED); setBaseUri("/"); when(request.getProperty(SpanCustomizer.class.getName())).thenReturn("eyeballs"); listener.onEvent(requestEvent); verifyNoMoreInteractions(parser); }
@Test public void onEvent_ignoresNotFinished() { for (RequestEvent.Type type : RequestEvent.Type.values()) { if (type == RequestEvent.Type.FINISHED) return; setEventType(type); listener.onEvent(requestEvent); verifyNoMoreInteractions(span); } }