### Question:
Terminal { public String toString() { StringBuilder sb = new StringBuilder(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { sb.append((char) (screen[y * width + x] & 0xffff)); } sb.append("\n"); } 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 testToString() { StringBuilder expected = new StringBuilder(); for (int i = 0; i < 24; i++) { for (int j = 0; j < 80; j++) { expected.append(" "); } expected.append("\n"); } assertArrayEquals(expected.toString().getBytes(), term.toString().getBytes()); expected = new StringBuilder(); expected.append("this thing better work"); int remainingLine = 80 - expected.length(); for (int i = 0; i < remainingLine; i++) { expected.append(" "); } expected.append("\n"); for (int i = 0; i < 23; i++) { for (int j = 0; j < 80; j++) { expected.append(" "); } expected.append("\n"); } term.write("this thing better work"); assertArrayEquals(expected.toString().getBytes(), term.toString().getBytes()); }