### Question:
HtmlMessagesRenderer extends HtmlMessagesRendererBase { @Override public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException { super.encodeEnd(facesContext, component); if (component instanceof ClientBehaviorHolder) { Map<String, List<ClientBehavior>> behaviors = ((ClientBehaviorHolder) component).getClientBehaviors(); if (!behaviors.isEmpty()) { ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, facesContext.getResponseWriter()); } } renderMessages(facesContext, component, false, true); }  @Override void encodeEnd(FacesContext facesContext, UIComponent component);  }### Answer:
@Test public void testRenderSpanOnlyWhenNecessary3() throws Exception { facesContext.addMessage("test1", new FacesMessage(FacesMessage.SEVERITY_WARN, "warnSumary", "detailWarnSummary")); messages.setId("msgPanel"); messages.encodeEnd(facesContext); facesContext.renderResponse(); String output = writer.getWriter().toString(); Assert.assertTrue(output.contains("warnSumary")); Assert.assertTrue(!output.contains("span")); }
@Test public void testRenderSpanOnlyWhenNecessary4() throws Exception { facesContext.addMessage("test1", new FacesMessage(FacesMessage.SEVERITY_FATAL, "fatalSumary", "detailFatalSummary")); messages.setId("msgPanel"); messages.setFatalClass("fatalClass"); messages.encodeEnd(facesContext); facesContext.renderResponse(); String output = writer.getWriter().toString(); Assert.assertTrue(output.contains("fatalSumary")); Assert.assertTrue(output.contains("li class=\"fatalClass\"")); Assert.assertTrue(!output.contains("span")); }
@Test public void testRenderSpanOnlyWhenNecessary5() throws Exception { facesContext.addMessage("test1", new FacesMessage(FacesMessage.SEVERITY_FATAL, "fatalSumary", "detailFatalSummary")); messages.setId("msgPanel"); messages.setLayout("table"); messages.setFatalClass("fatalClass"); messages.encodeEnd(facesContext); facesContext.renderResponse(); String output = writer.getWriter().toString(); Assert.assertTrue(output.contains("fatalSumary")); Assert.assertTrue(output.contains("td class=\"fatalClass\"")); Assert.assertTrue(!output.contains("span")); }
@Test public void testRenderSpanOnlyWhenNecessary1() throws Exception { facesContext.addMessage("test1", new FacesMessage(FacesMessage.SEVERITY_WARN, "warnSumary", "detailWarnSummary")); messages.encodeEnd(facesContext); facesContext.renderResponse(); String output = writer.getWriter().toString(); Assert.assertTrue(output.contains("warnSumary")); Assert.assertTrue(!output.contains("span")); }
@Test public void testRenderSpanOnlyWhenNecessary2() throws Exception { facesContext.addMessage("test1", new FacesMessage(FacesMessage.SEVERITY_WARN, "warnSumary", "detailWarnSummary")); messages.setLayout("table"); messages.encodeEnd(facesContext); facesContext.renderResponse(); String output = writer.getWriter().toString(); Assert.assertTrue(output.contains("warnSumary")); Assert.assertTrue(!output.contains("span")); }