### Question:
DigestAuthSupplier implements HttpAuthSupplier { public String getAuthorization(AuthorizationPolicy authPolicy, URI currentURI, Message message, String fullHeader) { if (authPolicy == null || (authPolicy.getUserName() == null && authPolicy.getPassword() == null)) { return null; } if (fullHeader == null) { DigestInfo di = authInfo.get(currentURI); if (di != null) { return di.generateAuth(getAuthURI(currentURI), authPolicy.getUserName(), authPolicy.getPassword()); } return null; } HttpAuthHeader authHeader = new HttpAuthHeader(fullHeader); if (authHeader.authTypeIsDigest()) { Map<String, String> map = authHeader.getParams(); if ("auth".equals(map.get("qop")) || !map.containsKey("qop")) { DigestInfo di = new DigestInfo(); di.qop = map.get("qop"); di.realm = map.get("realm"); di.nonce = map.get("nonce"); di.opaque = map.get("opaque"); if (map.containsKey("algorithm")) { di.algorithm = map.get("algorithm"); } if (map.containsKey("charset")) { di.charset = map.get("charset"); } di.method = (String)message.get(Message.HTTP_REQUEST_METHOD); if (di.method == null) { di.method = "POST"; } authInfo.put(currentURI, di); return di.generateAuth(getAuthURI(currentURI), authPolicy.getUserName(), authPolicy.getPassword()); } } return null; }  boolean requiresRequestCaching(); String getAuthorization(AuthorizationPolicy authPolicy,
                                   URI currentURI,
                                   Message message,
                                   String fullHeader); String createCnonce();  }### Answer:
@Test public void testEncode() throws Exception { String origNonce = "MTI0ODg3OTc5NzE2OTplZGUyYTg0Yzk2NTFkY2YyNjc1Y2JjZjU2MTUzZmQyYw=="; String fullHeader = "Digest realm=\"MyCompany realm.\", qop=\"auth\"," + "nonce=\"" + origNonce + "\""; DigestAuthSupplier authSupplier = new DigestAuthSupplier() { @Override public String createCnonce() { return "27db039b76362f3d55da10652baee38c"; } }; AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy(); authorizationPolicy.setUserName("testUser"); authorizationPolicy.setPassword("testPassword"); URI uri = new URI("http: Message message = new MessageImpl(); String authToken = authSupplier .getAuthorization(authorizationPolicy, uri, message, fullHeader); HttpAuthHeader authHeader = new HttpAuthHeader(authToken); assertTrue(authHeader.authTypeIsDigest()); Map<String, String> params = authHeader.getParams(); Map<String, String> expectedParams = new HashMap<>(); expectedParams.put("response", "28e616b6868f60aaf9b19bb5b172f076"); expectedParams.put("cnonce", "27db039b76362f3d55da10652baee38c"); expectedParams.put("username", "testUser"); expectedParams.put("nc", "00000001"); expectedParams.put("nonce", origNonce); expectedParams.put("realm", "MyCompany realm."); expectedParams.put("qop", "auth"); expectedParams.put("uri", ""); expectedParams.put("algorithm", "MD5"); assertEquals(expectedParams, params); }