@Test
public void testServletLazilyLoadsRecorder() throws IOException, ServletException {

    AWSXRayServletFilter servletFilter = new AWSXRayServletFilter("test");
    AsyncContext asyncContext = mock(AsyncContext.class);
    AWSXRayRecorder customRecorder = Mockito.spy(getMockRecorder());
    AWSXRay.setGlobalRecorder(customRecorder);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
    when(request.getMethod()).thenReturn("TEST_METHOD");
    when(request.isAsyncStarted()).thenReturn(true);
    when(request.getAsyncContext()).thenReturn(asyncContext);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain chain = mockChain(request, response);
    AsyncEvent event = mock(AsyncEvent.class);
    when(event.getSuppliedRequest()).thenReturn(request);
    when(event.getSuppliedResponse()).thenReturn(response);
    servletFilter.doFilter(request, response, chain);
    Assert.assertNull(AWSXRay.getTraceEntity());
    AWSXRayServletAsyncListener listener = (AWSXRayServletAsyncListener) Whitebox.getInternalState(servletFilter, "listener");
    listener.onComplete(event);
    verify(customRecorder.getEmitter(), Mockito.times(1)).sendSegment(Mockito.any());
}