BodyRenderer extends HtmlBasicRenderer { @Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("body", component); writeIdAttributeIfNecessary(context, writer, component); String styleClass = (String) component.getAttributes().get("styleClass"); if (styleClass != null && styleClass.length() != 0) { writer.writeAttribute("class", styleClass, "styleClass"); } RenderKitUtils.renderPassThruAttributes(context, writer, component, BODY_ATTRIBUTES); }  @Override void decode(FacesContext context, UIComponent component); @Override void encodeBegin(FacesContext context, UIComponent component); @Override void encodeChildren(FacesContext context, UIComponent component); @Override void encodeEnd(FacesContext context, UIComponent component); @Override boolean getRendersChildren();  }
@Test public void testEncodeBegin() throws Exception { StringWriter writer = new StringWriter(); ResponseWriter testResponseWriter = new TestResponseWriter(writer); FacesContext facesContext = PowerMock.createPartialMock(FacesContext.class, "getResponseWriter"); BodyRenderer bodyRenderer = new BodyRenderer(); HtmlBody htmlBody = new HtmlBody(); htmlBody.getAttributes().put("styleClass", "myclass"); expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes(); PowerMock.replay(facesContext); bodyRenderer.encodeBegin(facesContext, htmlBody); PowerMock.verify(facesContext); String html = writer.toString(); assertTrue(html.contains("<body")); assertTrue(html.contains("class=\"myclass\"")); }