@Test
public void testWrite() throws IOException, ServletException {

    ApplicationContext applicationContext = createMock(ServletApplicationContext.class);
    ServletContext servletContext = createMock(ServletContext.class);
    GenericServlet servlet = createMockBuilder(GenericServlet.class).createMock();
    ServletConfig servletConfig = createMock(ServletConfig.class);
    ObjectWrapper objectWrapper = createMock(ObjectWrapper.class);
    expect(servletConfig.getServletContext()).andReturn(servletContext);
    replay(servlet, servletConfig);
    servlet.init(servletConfig);
    ServletContextHashModel servletContextHashModel = new ServletContextHashModel(servlet, objectWrapper);
    expect(applicationContext.getContext()).andReturn(servletContext).anyTimes();
    expect(servletContext.getRealPath(isA(String.class))).andReturn(null).anyTimes();
    URL resource = getClass().getResource("/test.ftl");
    expect(servletContext.getResource(isA(String.class))).andReturn(resource).anyTimes();
    expect(servletContext.getAttribute(ATTR_APPLICATION_MODEL)).andReturn(servletContextHashModel);
    expect(servletContext.getAttribute(ATTR_JSP_TAGLIBS_MODEL)).andReturn(null);
    replay(applicationContext, servletContext, objectWrapper);
    FreemarkerRenderer renderer = FreemarkerRendererBuilder
            .createInstance().setApplicationContext(applicationContext)
            .setParameter("TemplatePath", "/")
            .setParameter("NoCache", "true")
            .setParameter("ContentType", "text/html")
            .setParameter("template_update_delay", "0")
            .setParameter("default_encoding", "ISO-8859-1")
            .setParameter("number_format", "0.##########").build();
    ServletRequest request = createMock(ServletRequest.class);
    HttpServletRequest httpRequest = createMock(HttpServletRequest.class);
    HttpServletResponse response = createMock(HttpServletResponse.class);
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    HttpRequestHashModel requestModel = new HttpRequestHashModel(httpRequest, response, objectWrapper);
    HttpRequestParametersHashModel parametersModel = new HttpRequestParametersHashModel(httpRequest);
    expect(request.getRequest()).andReturn(httpRequest);
    expect(request.getResponse()).andReturn(response);
    expect(request.getPrintWriter()).andReturn(printWriter);
    expect(httpRequest.getSession(false)).andReturn(null);
    expect(httpRequest.getAttribute(ATTR_REQUEST_MODEL)).andReturn(requestModel);
    expect(httpRequest.getAttribute(ATTR_REQUEST_PARAMETERS_MODEL)).andReturn(parametersModel);
    response.setContentType("text/html; charset=ISO-8859-1");
    response.setHeader(eq("Cache-Control"), isA(String.class));
    response.setHeader("Pragma", "no-cache");
    response.setHeader(eq("Expires"), isA(String.class));
    replay(request, httpRequest, response);
    renderer.render("hello", request);
    stringWriter.close();
    assertTrue(stringWriter.toString().startsWith("Hello!"));
    verify(applicationContext, servletContext, request, httpRequest,
            response, servlet, servletConfig, objectWrapper);
}