### Question:
PathDigest implements Function<PathMetadata, String> { @Override public String apply(PathMetadata pathDescriptor) { byte[] checksum = messageDigest.digest(serialize(pathDescriptor)); return Base64.encodeBase64String(checksum); } PathDigest();  PathDigest(String algorithm); @Override String apply(PathMetadata pathDescriptor); static byte[] serialize(PathMetadata pathDescriptor); static final String DEFAULT_MESSAGE_DIGEST_ALGORITHM; }### Answer:
@Test public void typical() throws Exception { when(path.toUri()).thenReturn(new URI(FILE_LOCATION)); when(checksum.getAlgorithmName()).thenReturn(MD5); when(checksum.getLength()).thenReturn(1); when(checksum.getBytes()).thenReturn(new byte[] {}); PathMetadata pathDescriptor = new PathMetadata(path, LAST_MODIFIED, checksum, ImmutableList.<PathMetadata> of()); String base64Digest = function.apply(pathDescriptor); assertThat(base64Digest.matches(BASE_64_REGEX), is(true)); }
@Test public void noChecksum() throws Exception { when(path.toUri()).thenReturn(new URI(FILE_LOCATION)); PathMetadata pathDescriptor = new PathMetadata(path, LAST_MODIFIED, checksum, ImmutableList.<PathMetadata> of()); String base64Digest = function.apply(pathDescriptor); assertThat(base64Digest.matches(BASE_64_REGEX), is(true)); }