### Question:
HttpBasicAuth implements Authentication { @Override public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) { if (username == null && password == null) { return; } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }  String getUsername(); void setUsername(String username); String getPassword(); void setPassword(String password); @Override void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams);  }### Answer:
@Test public void testApplyToParams() { List<Pair> queryParams = new ArrayList<Pair>(); Map<String, String> headerParams = new HashMap<String, String>(); Map<String, String> cookieParams = new HashMap<String, String>(); auth.setUsername("my-username"); auth.setPassword("my-password"); auth.applyToParams(queryParams, headerParams, cookieParams); assertEquals(0, queryParams.size()); assertEquals(0, cookieParams.size()); assertEquals(1, headerParams.size()); String expected = "Basic bXktdXNlcm5hbWU6bXktcGFzc3dvcmQ="; assertEquals(expected, headerParams.get("Authorization")); auth.setUsername(null); auth.applyToParams(queryParams, headerParams, cookieParams); expected = "Basic Om15LXBhc3N3b3Jk"; assertEquals(expected, headerParams.get("Authorization")); auth.setUsername("my-username"); auth.setPassword(null); auth.applyToParams(queryParams, headerParams, cookieParams); expected = "Basic bXktdXNlcm5hbWU6"; assertEquals(expected, headerParams.get("Authorization")); }