### Question:
HttpHeaderParser { public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HEADER_CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; i++) { String[] pair = params[i].trim().split("="); if (pair.length == 2) { if (pair[0].equals("charset")) { return pair[1]; } } } } return defaultCharset; }  static Cache.Entry parseCacheHeaders(NetworkResponse response); static long parseDateAsEpoch(String dateStr); static String parseCharset(Map<String, String> headers, String defaultCharset); static String parseCharset(Map<String, String> headers);  }### Answer:
@Test public void parseCharset() { headers.put("Content-Type", "text/plain; charset=utf-8"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "text/plain; charset=utf-8"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "ISO-8859-1")); headers.put("Content-Type", "text/plain; charset=utf-8 "); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "text/plain; charset=utf-8; frozzle=bar"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); headers.clear(); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); headers.clear(); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); headers.put("Content-Type", "text/plain; charset="); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "text/plain"); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "application/json"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); headers.put("Content-Type", "text/plain;"); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); }