### Question:
HTMLLayout extends HTMLLayoutBase<ILoggingEvent> { public String doLayout(ILoggingEvent event) { StringBuilder buf = new StringBuilder(); startNewTableIfLimitReached(buf); boolean odd = true; if (((counter++) & 1) == 0) { odd = false; } String level = event.getLevel().toString().toLowerCase(Locale.US); buf.append(LINE_SEPARATOR); buf.append("<tr class=\""); buf.append(level); if (odd) { buf.append(" odd\">"); } else { buf.append(" even\">"); } buf.append(LINE_SEPARATOR); Converter<ILoggingEvent> c = head; while (c != null) { appendEventToBuffer(buf, c, event); c = c.getNext(); } buf.append("</tr>"); buf.append(LINE_SEPARATOR); if (event.getThrowableProxy() != null) { throwableRenderer.render(buf, event); } return buf.toString(); } HTMLLayout(); @Override void start(); String doLayout(ILoggingEvent event); IThrowableRenderer<ILoggingEvent> getThrowableRenderer(); void setThrowableRenderer(IThrowableRenderer<ILoggingEvent> throwableRenderer);  }### Answer:
@Test public void testDoLayout() throws Exception { ILoggingEvent le = createLoggingEvent(); String result = layout.getFileHeader(); result += layout.getPresentationHeader(); result += layout.doLayout(le); result += layout.getPresentationFooter(); result += layout.getFileFooter(); Document doc = parseOutput(result); Element rootElement = doc.getRootElement(); rootElement.toString(); assertEquals(2, rootElement.elements().size()); Element bodyElement = (Element) rootElement.elements().get(1); Element tableElement = (Element) bodyElement.elements().get(3); assertEquals("table", tableElement.getName()); Element trElement = (Element) tableElement.elements().get(1); { Element tdElement = (Element) trElement.elements().get(0); assertEquals("DEBUG", tdElement.getText()); } { Element tdElement = (Element) trElement.elements().get(1); String regex = ClassicTestConstants.NAKED_MAIN_REGEX; System.out.println(tdElement.getText()); assertTrue(tdElement.getText().matches(regex)); } { Element tdElement = (Element) trElement.elements().get(2); assertEquals("test message", tdElement.getText()); } }
@SuppressWarnings("unchecked") @Test public void layoutWithException() throws Exception { layout.setPattern("%level %thread %msg %ex"); LoggingEvent le = createLoggingEvent(); le.setThrowableProxy(new ThrowableProxy(new Exception("test Exception"))); String result = layout.doLayout(le); String stringToParse = layout.getFileHeader(); stringToParse = stringToParse + layout.getPresentationHeader(); stringToParse += result; stringToParse += "</table></body></html>"; Document doc = parseOutput(stringToParse); Element rootElement = doc.getRootElement(); Element bodyElement = rootElement.element("body"); Element tableElement = bodyElement.element("table"); List<Element> trElementList = tableElement.elements(); Element exceptionRowElement = trElementList.get(2); Element exceptionElement = exceptionRowElement.element("td"); assertEquals(3, tableElement.elements().size()); assertTrue(exceptionElement.getText().contains( "java.lang.Exception: test Exception")); }
@Test @Ignore public void rawLimit() throws Exception { StringBuilder sb = new StringBuilder(); String header = layout.getFileHeader(); assertTrue(header .startsWith("<!DOCTYPE html PUBLIC \"- sb.append(header); sb.append(layout.getPresentationHeader()); for (int i = 0; i < CoreConstants.TABLE_ROW_LIMIT * 3; i++) { sb.append(layout.doLayout(new LoggingEvent(this.getClass().getName(), root, Level.DEBUG, "test message" + i, null, null))); } sb.append(layout.getPresentationFooter()); sb.append(layout.getFileFooter()); parseOutput(sb.toString()); }