### Question:
HttpResponse { @Override public String toString() { StringBuilder builder = new StringBuilder(50); builder.append("HTTP/1.1 ").append(status).append('\n'); for (Map.Entry<String, List<String>> h : headers.entrySet()) { for (String v : h.getValue()) { builder.append(h.getKey()).append(": ").append(v).append('\n'); } } builder.append("\n... ") .append(data.length) .append(" bytes ...\n"); return builder.toString(); } HttpResponse(int status, Map<String, List<String>> headers);  HttpResponse(int status, Map<String, List<String>> headers, byte[] data); int status(); Map<String, List<String>> headers(); String header(String k); Instant dateHeader(String k); byte[] entity(); String entityAsString(); HttpResponse decompress(); @Override String toString();  }### Answer:
@Test public void toStringEmpty() { HttpResponse res = new HttpResponse(200, Collections.emptyMap()); String expected = "HTTP/1.1 200\n\n... 0 bytes ...\n"; Assertions.assertEquals(expected, res.toString()); }
@Test public void toStringContent() { byte[] entity = "content".getBytes(StandardCharsets.UTF_8); HttpResponse res = new HttpResponse(200, Collections.emptyMap(), entity); String expected = "HTTP/1.1 200\n\n... 7 bytes ...\n"; Assertions.assertEquals(expected, res.toString()); }
@Test public void toStringHeaders() { Map<String, List<String>> headers = new HashMap<>(); headers.put("Date", Collections.singletonList("Mon, 27 Jul 2012 17:21:03 GMT")); headers.put("Content-Type", Collections.singletonList("application/json")); byte[] entity = "{}".getBytes(StandardCharsets.UTF_8); HttpResponse res = new HttpResponse(200, headers, entity); String expected = "HTTP/1.1 200\nContent-Type: application/json\nDate: Mon, 27 Jul 2012 17:21:03 GMT\n\n... 2 bytes ...\n"; Assertions.assertEquals(expected, res.toString()); }