@Test
public void testGetApplicationContext() throws TemplateModelException {

    GenericServlet servlet = createMock(GenericServlet.class);
    ServletContext servletContext = createMock(ServletContext.class);
    ObjectWrapper objectWrapper = createMock(ObjectWrapper.class);
    ApplicationContext applicationContext = createMock(ApplicationContext.class);
    expect(servlet.getServletContext()).andReturn(servletContext).times(2);
    expect(servletContext.getAttribute(ApplicationAccess
            .APPLICATION_CONTEXT_ATTRIBUTE)).andReturn(applicationContext);
    replay(servlet, objectWrapper);
    ServletContextHashModel servletContextModel = new ServletContextHashModel(servlet, objectWrapper);
    expect(model.get("Application")).andReturn(servletContextModel);
    replay(template, model, servletContext);
    env = new Environment(template, model, writer);
    locale = Locale.ITALY;
    env.setLocale(locale);
    assertEquals(applicationContext, FreemarkerRequestUtil.getApplicationContext(env));
    verify(template, model, servlet, servletContext, objectWrapper);
}