### Question:
DigestVerifier { public void inspectDigest(byte[] messageBody, Map<String, List<String>> responseHeaders) { LOG.fine("Starting digest verification"); if (responseHeaders.containsKey("Digest")) { MessageDigest messageDigest = SignatureHeaderUtils .createMessageDigestWithAlgorithm(splitDigestHeader(responseHeaders.get("Digest").get(0)).get(0)); messageDigest.update(messageBody); byte[] generatedDigest = messageDigest.digest(); byte[] headerDigest = Base64.getDecoder() .decode(splitDigestHeader(responseHeaders.get("Digest").get(0)).get(1)); if (!Arrays.equals(generatedDigest, headerDigest)) { throw new DifferentDigestsException("the digest does not match the body of the message"); } } else { throw new MissingDigestException("found no digest header"); } LOG.fine("Finished digest verification"); }  void inspectDigest(byte[] messageBody, Map<String, List<String>> responseHeaders);  }### Answer:
@Test public void validUnalteredDigest() { Map<String, List<String>> headers = new HashMap<>(); createDigestHeader(MESSAGE_BODY, headers, DefaultSignatureConstants.DIGEST_ALGORITHM); digestVerifier.inspectDigest(MESSAGE_BODY.getBytes(), headers); }
@Test(expected = DifferentDigestsException.class) public void differentDigestsFails() { Map<String, List<String>> headers = new HashMap<>(); createDigestHeader(MESSAGE_BODY, headers, DefaultSignatureConstants.DIGEST_ALGORITHM); String digest = "SHA-256=HEYHEYHEYHEY"; headers.replace("Digest", Collections.singletonList(digest)); digestVerifier.inspectDigest(MESSAGE_BODY.getBytes(), headers); }
@Test(expected = DifferentDigestsException.class) public void digestFailureAlteredMessageFails() { Map<String, List<String>> headers = new HashMap<>(); createDigestHeader(MESSAGE_BODY, headers, DefaultSignatureConstants.DIGEST_ALGORITHM); digestVerifier.inspectDigest("TEST".getBytes(), headers); }
@Test(expected = DigestFailureException.class) public void digestFailureFails() { Map<String, List<String>> headers = new HashMap<>(); createDigestHeader(MESSAGE_BODY, headers, DefaultSignatureConstants.DIGEST_ALGORITHM); String digest = "HELLO=HEYHEYHEYHEY"; headers.replace("Digest", Collections.singletonList(digest)); digestVerifier.inspectDigest(MESSAGE_BODY.getBytes(), headers); }
@Test(expected = DigestFailureException.class) public void digestFailureAlteredDigestStringFails() { Map<String, List<String>> headers = new HashMap<>(); createDigestHeader(MESSAGE_BODY, headers, DefaultSignatureConstants.DIGEST_ALGORITHM); String digest = "BOERFKSEFK=VSJEFKSE=SRJSPAWKD"; headers.replace("Digest", Collections.singletonList(digest)); digestVerifier.inspectDigest(MESSAGE_BODY.getBytes(), headers); }
@Test(expected = DigestFailureException.class) public void digestFailureEmptyDigestStringFails() { Map<String, List<String>> headers = new HashMap<>(); createDigestHeader(MESSAGE_BODY, headers, DefaultSignatureConstants.DIGEST_ALGORITHM); String digest = ""; headers.replace("Digest", Collections.singletonList(digest)); digestVerifier.inspectDigest(MESSAGE_BODY.getBytes(), headers); }