FreemarkerRequestUtil { public static ServletContextHashModel getServletContextHashModel( Environment env) { try { return (ServletContextHashModel) env.getDataModel().get( FreemarkerServlet.KEY_APPLICATION); } catch (TemplateModelException e) { throw new NotAvailableFreemarkerServletException( "Exception got when obtaining the application hash model", e); } } private  FreemarkerRequestUtil(); static HttpRequestHashModel getRequestHashModel(Environment env); static ServletContextHashModel getServletContextHashModel(
            Environment env); static ApplicationContext getApplicationContext(
            Environment env);  }
@Test public void testGetServletContextHashModel() throws TemplateModelException { GenericServlet servlet = createMock(GenericServlet.class); ServletContext servletContext = createMock(ServletContext.class); ObjectWrapper objectWrapper = createMock(ObjectWrapper.class); expect(servlet.getServletContext()).andReturn(servletContext); 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(servletContextModel, FreemarkerRequestUtil.getServletContextHashModel(env)); verify(template, model, servlet, servletContext, objectWrapper); }
@Test(expected = NotAvailableFreemarkerServletException.class) public void testGetServletContextHashModelException() throws TemplateModelException { GenericServlet servlet = createMock(GenericServlet.class); ObjectWrapper objectWrapper = createMock(ObjectWrapper.class); replay(servlet, objectWrapper); expect(model.get("Application")).andThrow(new TemplateModelException()); replay(template, model); try { env = new Environment(template, model, writer); locale = Locale.ITALY; env.setLocale(locale); FreemarkerRequestUtil.getServletContextHashModel(env); } finally { verify(template, model, servlet, objectWrapper); } }