### Question:
Terminal { public synchronized String dump() throws InterruptedException { StringBuilder sb = new StringBuilder(); int prev_attr = -1; int cx = Math.min(this.cx, width - 1); int cy = this.cy; sb.append("<div><pre class='term'>"); for (int y = 0; y < height; y++) { int wx = 0; for (int x = 0; x < width; x++) { int d = screen[y * width + x]; int c = d & 0xffff; int a = d >> 16; if (cy == y && cx == x && vt100_mode_cursor) { a = a & 0xfff0 | 0x000c; } if (a != prev_attr) { if (prev_attr != -1) { sb.append("</span>"); } int bg = a & 0x000f; int fg = (a & 0x00f0) >> 4; boolean inv = (a & 0x0200) != 0; boolean inv2 = vt100_mode_inverse; if (inv && !inv2 || inv2 && !inv) { int i = fg; fg = bg; bg = i; } if ((a & 0x0400) != 0) { fg = 0x0c; } String ul; if ((a & 0x0100) != 0) { ul = " ul"; } else { ul = ""; } String b; if ((a & 0x0800) != 0) { b = " b"; } else { b = ""; } sb.append("<span class='f").append(fg).append(" b").append(bg).append(ul).append(b).append("'>"); prev_attr = a; } switch (c) { case '&': sb.append("&amp;"); break; case '<': sb.append("&lt;"); break; case '>': sb.append("&gt;"); break; default: wx += utf8_charwidth(c); if (wx <= width) { sb.append((char) c); } break; } } sb.append("\n"); } sb.append("</span></pre></div>"); return sb.toString(); } Terminal();  Terminal(int width, int height); synchronized boolean setSize(int w, int h); synchronized String read(); synchronized String pipe(String d); synchronized boolean write(String d); synchronized String dump(); String toString();  }### Answer:
@Test public void testDump() { String expected = ""; String tags = "<div><pre class='term'>"; try { expected = term.dump(); assertTrue(expected.contains(tags)); term.write("& < >"); expected = term.dump(); assertTrue(expected.contains("&amp; &lt; &gt;")); term.write("\u001b[?5h"); expected = term.dump(); assertTrue(expected.contains("&amp; &lt; &gt;")); term.write("\u001b[4m"); term.write("underlinedText"); expected = term.dump(); assertTrue(expected.contains("underlinedText")); term.write("\u001b[1m"); term.write("boldedText"); expected = term.dump(); assertTrue(expected.contains("boldedText")); } catch (Exception e) { fail("Dump should not have thrown an exception"); } }