FreemarkerModelBody extends AbstractModelBody { @Override public void evaluate(Writer writer) throws IOException { if (templateDirectiveBody == null) { return; } try { templateDirectiveBody.render(writer); } catch (TemplateException e) { throw new IOException("TemplateException when rendering body", e); } } FreemarkerModelBody(Writer defaultWriter, TemplateDirectiveBody templateDirectiveBody); @Override void evaluate(Writer writer);  }
@Test public void testEvaluateWriter() throws TemplateException, IOException { TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class); Writer writer = createMock(Writer.class); body.render(writer); replay(body, writer); FreemarkerModelBody modelBody = new FreemarkerModelBody(null, body); modelBody.evaluate(writer); verify(body, writer); }
@Test public void testEvaluateWriterNull() throws TemplateException, IOException { Writer writer = createMock(Writer.class); replay(writer); FreemarkerModelBody modelBody = new FreemarkerModelBody(null, null); modelBody.evaluate(writer); verify(writer); }
@Test(expected = IOException.class) public void testEvaluateWriterException() throws TemplateException, IOException { TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class); Writer writer = createMock(Writer.class); body.render(writer); expectLastCall().andThrow(new TemplateException(null)); replay(body, writer); try { FreemarkerModelBody modelBody = new FreemarkerModelBody(null, body); modelBody.evaluate(writer); } finally { verify(body, writer); } }