FreemarkerRequestUtil { public static HttpRequestHashModel getRequestHashModel(Environment env) { try { return (HttpRequestHashModel) env.getDataModel().get( FreemarkerServlet.KEY_REQUEST); } catch (TemplateModelException e) { throw new NotAvailableFreemarkerServletException( "Exception got when obtaining the request hash model", e); } } private  FreemarkerRequestUtil(); static HttpRequestHashModel getRequestHashModel(Environment env); static ServletContextHashModel getServletContextHashModel(
            Environment env); static ApplicationContext getApplicationContext(
            Environment env);  }
@Test public void testGetRequestHashModel() throws TemplateModelException { HttpServletRequest request = createMock(HttpServletRequest.class); ObjectWrapper objectWrapper = createMock(ObjectWrapper.class); HttpRequestHashModel requestModel = new HttpRequestHashModel(request, objectWrapper); expect(model.get("Request")).andReturn(requestModel); replay(template, model, request, objectWrapper); env = new Environment(template, model, writer); locale = Locale.ITALY; env.setLocale(locale); assertEquals(requestModel, FreemarkerRequestUtil.getRequestHashModel(env)); verify(template, model, request, objectWrapper); }
@Test(expected = NotAvailableFreemarkerServletException.class) public void testGetRequestHashModelException() throws TemplateModelException { HttpServletRequest request = createMock(HttpServletRequest.class); ObjectWrapper objectWrapper = createMock(ObjectWrapper.class); expect(model.get("Request")).andThrow(new TemplateModelException()); replay(template, model, request, objectWrapper); try { env = new Environment(template, model, writer); locale = Locale.ITALY; env.setLocale(locale); FreemarkerRequestUtil.getRequestHashModel(env); } finally { verify(template, model, request, objectWrapper); } }