@Test
public void testFilterChain() throws Exception {

    // Mock up the service references
    ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
    EasyMock.replay(filterReference);
    ServiceReference[] serviceReferences = {filterReference, filterReference};
    // Mock up the bundle context
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
        .andReturn(serviceReferences);
    EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
    EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
    EasyMock.replay(bundleContext);
    // Set up the secure http context
    httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
    // Ensure that the httpContext returns false, since the filter has committed the response
    HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
    EasyMock.replay(request);
    HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
    EasyMock.expect(response.isCommitted()).andReturn(false); // doNothingFilter should not commit the response
    EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
    EasyMock.expect(response.isCommitted()).andReturn(false);
    EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the
                                                             // response
    EasyMock.replay(response);
    assertFalse(httpContext.handleSecurity(request, response));
    // Ensure that the appropriate filters were called
    assertTrue(doNothingFilter.called);
    assertTrue(commitFilter.called);
    assertFalse(accessDeniedFilter.called);
}