FreemarkerAutotagRuntime implements AutotagRuntime<Request>, TemplateDirectiveModel { @Override public Request createRequest() { return FreemarkerRequest.createServletFreemarkerRequest(FreemarkerRequestUtil.getApplicationContext(env), env); }  @SuppressWarnings("unchecked") @Override void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body); @Override Request createRequest(); @Override ModelBody createModelBody(); @Override T getParameter(String name, Class<T> type, T defaultValue);  }
@Test public void testCreateRequest() throws IOException, TemplateModelException{ @SuppressWarnings("unchecked") Map<String, TemplateModel> params = createMock(Map.class); Template template = createMock(Template.class); TemplateHashModel rootDataModel = createMock(TemplateHashModel.class); Writer out = createMock(Writer.class); TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class); GenericServlet servlet = createMock(GenericServlet.class); ObjectWrapper wrapper = createMock(ObjectWrapper.class); ServletContext servletContext = createMock(ServletContext.class); ApplicationContext applicationContext = createMock(ApplicationContext.class); HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class); HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class); expect(template.getMacros()).andReturn(new HashMap<String, Macro>()); expect(servlet.getServletContext()).andReturn(servletContext) .anyTimes(); expect( servletContext .getAttribute(ApplicationAccess.APPLICATION_CONTEXT_ATTRIBUTE)) .andReturn(applicationContext); replay(servlet, wrapper, servletContext, applicationContext, httpServletRequest, httpServletResponse); ServletContextHashModel servletContextHashModel = new ServletContextHashModel( servlet, wrapper); HttpRequestHashModel httpRequestHashModel = new HttpRequestHashModel( httpServletRequest, httpServletResponse, wrapper); expect(rootDataModel.get(FreemarkerServlet.KEY_APPLICATION)).andReturn( servletContextHashModel); expect(rootDataModel.get(FreemarkerServlet.KEY_REQUEST)).andReturn( httpRequestHashModel); replay(template, rootDataModel, out); Environment env = new Environment(template, rootDataModel, out); replay(params, body); FreemarkerAutotagRuntime runtime = new FreemarkerAutotagRuntime(); runtime.execute(env, params, new TemplateModel[0], body); Request request = runtime.createRequest(); assertTrue(request instanceof FreemarkerRequest); verify(servlet, wrapper, servletContext, applicationContext, httpServletRequest, httpServletResponse, template, rootDataModel, out, params, body); }