### Question:
Headers { static void logProtocolHeaders(Logger logger, Level level, Map<String, List<Object>> headersMap, boolean logSensitiveHeaders) { if (logger.isLoggable(level)) { for (Map.Entry<String, List<Object>> entry : headersMap.entrySet()) { String key = entry.getKey(); boolean sensitive = !logSensitiveHeaders && SENSITIVE_HEADERS.contains(key); List<Object> headerList = sensitive ? SENSITIVE_HEADER_MARKER : entry.getValue(); for (Object value : headerList) { logger.log(level, key + ": " + (value == null ? "<null>" : value.toString())); } } } } Headers(Message message);  Headers(); static String getUserAgent(); Map<String, List<String>> headerMap(); void writeSessionCookies(Map<String, Cookie> sessionCookies); void removeAuthorizationHeaders(); void setAuthorization(String authorization); void setProxyAuthorization(String authorization); static Map<String, List<String>> getSetProtocolHeaders(final Message message); void readFromConnection(HttpURLConnection connection); void setProtocolHeadersInConnection(HttpURLConnection connection); String determineContentType(); String getAuthorization(); static SimpleDateFormat getHttpDateFormat(); static String toHttpDate(Date date); static String toHttpLanguage(Locale locale); static final String KEY_HTTP_CONNECTION; static final String ADD_HEADERS_PROPERTY; static final String PROTOCOL_HEADERS_CONTENT_TYPE; static final String HTTP_HEADERS_SETCOOKIE; static final String HTTP_HEADERS_LINK; static final String EMPTY_REQUEST_PROPERTY; }### Answer:
@Test public void logProtocolHeadersTest() { Map<String, List<Object>> headerMap = new HashMap<>(); headerMap.put("Normal-Header", Arrays.asList("normal")); headerMap.put("Multivalue-Header", Arrays.asList("first", "second")); headerMap.put("Authorization", Arrays.asList("myPassword")); headerMap.put("Null-Header", Arrays.asList((String)null)); Logger logger = Logger.getAnonymousLogger(); logger.setUseParentHandlers(false); logger.setLevel(Level.INFO); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(new Handler() { @Override public void publish(LogRecord record) { String msg = record.getMessage(); if (msg.startsWith("Normal-Header")) { assertTrue("Unexpected output for normal header - expected Normal-Header: normal, received " + msg, "Normal-Header: normal".equals(msg)); } else if (msg.startsWith("Multivalue-Header")) { assertTrue("Unexpected output for multi-value header - expected Multivalue-Header: first or " + "Multivalue-Header: second, received: " + msg, "Multivalue-Header: first".equals(msg) || "Multivalue-Header: second".equals(msg)); } else if (msg.startsWith("Authorization")) { assertTrue("Unexpected output for sensitive header - expected Authorization: ***, received " + msg, "Authorization: ***".equals(msg)); } else if (msg.startsWith("Null-Header")) { assertTrue("Unexpected output for null header - expected Null-Header: <null>, received " + msg, "Null-Header: <null>".equals(msg)); } else { fail("Unexpected header logged: " + msg); } } @Override public void flush() { } @Override public void close() throws SecurityException { } }); Headers.logProtocolHeaders(logger, Level.INFO, headerMap, false); }