HeadRenderer extends Renderer { @Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); encodeHeadResources(context); writer.endElement("head"); }  @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);  }
@Test public void testEncodeEnd() throws Exception { StringWriter writer = new StringWriter(); ResponseWriter testResponseWriter = new TestResponseWriter(writer); FacesContext facesContext = PowerMock.createPartialMockForAllMethodsExcept(FacesContext.class, "getCurrentInstance"); UIViewRoot viewRoot = PowerMock.createMock(UIViewRoot.class); HeadRenderer headRenderer = new HeadRenderer(); HtmlHead htmlHead = new HtmlHead(); expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes(); expect(facesContext.getViewRoot()).andReturn(viewRoot).anyTimes(); expect(viewRoot.getComponentResources(facesContext, "head")).andReturn(Collections.EMPTY_LIST).anyTimes(); PowerMock.replay(facesContext, viewRoot); headRenderer.encodeEnd(facesContext, htmlHead); PowerMock.verify(facesContext, viewRoot); String html = writer.toString(); assertTrue(html.contains("</head>")); }