@SuppressWarnings("unchecked")
@Test
public void testDoFilter() throws IOException, ServletException {

    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpServletResponse response = createMock(HttpServletResponse.class);
    FilterChain chain = createMock(FilterChain.class);
    ApplicationContext applicationContext = createMock(ApplicationContext.class);
    Map<String, Object> applicationScope = createMock(Map.class);
    TilesContainer container = createMock(TilesContainer.class);
    AttributeContext attributeContext = createMock(AttributeContext.class);
    expect(request.getAttribute("org.apache.tiles.decoration.PREVENT:tokenKey")).andReturn(null);
    expect(servletContext.getAttribute(ApplicationAccess.APPLICATION_CONTEXT_ATTRIBUTE))
            .andReturn(applicationContext);
    expect(applicationContext.getApplicationScope()).andReturn(applicationScope);
    expect(applicationScope.get("key")).andReturn(container);
    expect(container.getAttributeContext(isA(ServletRequest.class))).andReturn(attributeContext);
    request.setAttribute("org.apache.tiles.decoration.PREVENT:tokenKey", true);
    expect(request.getAttribute("javax.servlet.include.servlet_path")).andReturn(null);
    expect(request.getServletPath()).andReturn("/tiles");
    container.render(eq("definitionKey"), isA(ServletRequest.class));
    chain.doFilter(request, response);
    replay(servletContext, request, response, chain, applicationContext,
            applicationScope, container, attributeContext);
    filter.doFilter(request, response, chain);
    verify(request, response, chain, applicationContext, applicationScope, container, attributeContext);
}