FreemarkerAutotagRuntime implements AutotagRuntime<Request>, TemplateDirectiveModel { @Override public <T> T getParameter(String name, Class<T> type, T defaultValue) { return FreemarkerUtil.getAsObject((TemplateModel)params.get(name), type, defaultValue); }  @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 testGetParameter() throws TemplateModelException { Template template = createMock(Template.class); TemplateHashModel rootDataModel = createMock(TemplateHashModel.class); Writer out = createMock(Writer.class); expect(template.getMacros()).andReturn(new HashMap<String, Macro>()); replay(template, rootDataModel, out); Environment env = new Environment(template, rootDataModel, out); TemplateNumberModel model = createMock(TemplateNumberModel.class); expect(model.getAsNumber()).andReturn(new Integer(42)).anyTimes(); @SuppressWarnings("unchecked") Map<String, TemplateModel> params = createMock(Map.class); TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class); expect(params.get(eq("notnullParam"))).andReturn(model).anyTimes(); expect(params.get(eq("nullParam"))).andReturn(null).anyTimes(); replay(model, params, body); FreemarkerAutotagRuntime runtime = new FreemarkerAutotagRuntime(); runtime.execute(env, params, new TemplateModel[0], body); Object notnullParam = runtime.getParameter("notnullParam", Object.class, null); Object nullParam = runtime.getParameter("nullParam", Object.class, null); int notnullParamDefault = runtime.getParameter("notnullParam", Integer.class, new Integer(24)); int nullParamDefault = runtime.getParameter("nullParam", Integer.class, new Integer(24)); assertEquals(42, notnullParam); assertEquals(null, nullParam); assertEquals(42, notnullParamDefault); assertEquals(24, nullParamDefault); verify(template, rootDataModel, out, model, params, body); }