JspModelBody extends AbstractModelBody { @Override public void evaluate(Writer writer) throws IOException { if (jspFragment == null) { return; } try { jspFragment.invoke(writer); } catch (JspException e) { throw new IOException("JspException when evaluating the body", e); } } JspModelBody(JspFragment jspFragment, JspContext jspContext); @Override void evaluate(Writer writer);  }
@Test public void testEvaluateWriter() throws JspException, IOException { JspFragment body = createMock(JspFragment.class); PageContext pageContext = createMock(PageContext.class); JspWriter writer = createMock(JspWriter.class); expect(pageContext.getOut()).andReturn(null); body.invoke(writer); replay(body, pageContext, writer); JspModelBody modelBody = new JspModelBody(body, pageContext); modelBody.evaluate(writer); verify(body, pageContext, writer); }
@Test public void testEvaluateWriterNull() throws JspException, IOException { PageContext pageContext = createMock(PageContext.class); Writer writer = createMock(Writer.class); expect(pageContext.getOut()).andReturn(null); replay(writer, pageContext); JspModelBody modelBody = new JspModelBody(null, pageContext); modelBody.evaluate(writer); verify(writer, pageContext); }
@Test(expected = IOException.class) public void testEvaluateWriterException() throws JspException, IOException { PageContext pageContext = createMock(PageContext.class); JspFragment body = createMock(JspFragment.class); JspWriter writer = createMock(JspWriter.class); expect(pageContext.getOut()).andReturn(null); body.invoke(writer); expectLastCall().andThrow(new JspException()); replay(body, pageContext, writer); try { JspModelBody modelBody = new JspModelBody(body, pageContext); modelBody.evaluate(writer); } finally { verify(body, pageContext, writer); } }