@Test
public void testRequestExpired() throws IOException {

    Stanza emtpyStanza = BoshStanzaUtils.EMPTY_BOSH_RESPONSE;
    // addRequest
    HttpServletRequest httpServletRequest = mocksControl.createMock(HttpServletRequest.class);
    AsyncContext asyncContext = mocksControl.createMock(AsyncContext.class);
    expect(httpServletRequest.startAsync()).andReturn(asyncContext).atLeastOnce();
    expect(httpServletRequest.getAsyncContext()).andReturn(asyncContext).atLeastOnce();
    asyncContext.setTimeout(anyLong());
    httpServletRequest.setAttribute(eq(BOSH_REQUEST_ATTRIBUTE), EasyMock.<BoshRequest>notNull());
    expect(asyncContext.getRequest()).andReturn(httpServletRequest).atLeastOnce();
    asyncContext.dispatch();
    expectLastCall().atLeastOnce();
    Capture<AsyncListener> listenerCaptured = new Capture<AsyncListener>();
    asyncContext.addListener(EasyMock.<AsyncListener> capture(listenerCaptured));
    AsyncEvent asyncEvent = mocksControl.createMock(AsyncEvent.class);
    BoshRequest br = new BoshRequest(httpServletRequest, emtpyStanza, 1L);
    // requestExpired
    expect(httpServletRequest.getAttribute(BOSH_REQUEST_ATTRIBUTE)).andReturn(br);
    Capture<BoshResponse> responseCaptured = new Capture<BoshResponse>();
    httpServletRequest.setAttribute(eq(BOSH_RESPONSE_ATTRIBUTE), EasyMock.<BoshResponse> capture(responseCaptured));
    // write0
    mocksControl.replay();
    BoshBackedSessionContext boshBackedSessionContext = new BoshBackedSessionContext(serverRuntimeContext, stanzaProcessor, null, inactivityChecker);
    
    boshBackedSessionContext.insertRequest(br);
    listenerCaptured.getValue().onTimeout(asyncEvent);
    mocksControl.verify();
    assertEquals(new Renderer(emtpyStanza).getComplete(), new String(responseCaptured.getValue().getContent()));
    assertEquals(BoshServlet.XML_CONTENT_TYPE, responseCaptured.getValue().getContentType());
}