### Question:
CacheStorageFiles { DescriptorDigest getDigestFromFilename(Path layerFile) throws CacheCorruptedException { try { String hash = layerFile.getFileName().toString(); return DescriptorDigest.fromHash(hash); } catch (DigestException | IndexOutOfBoundsException ex) { throw new CacheCorruptedException( cacheDirectory, "Layer file did not include valid hash: " + layerFile, ex); } } CacheStorageFiles(Path cacheDirectory);   }### Answer:
@Test public void testGetDiffId() throws DigestException, CacheCorruptedException { Assert.assertEquals( DescriptorDigest.fromHash( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), TEST_CACHE_STORAGE_FILES.getDigestFromFilename( Paths.get( "layer", "file", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))); Assert.assertEquals( DescriptorDigest.fromHash( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), TEST_CACHE_STORAGE_FILES.getDigestFromFilename( Paths.get("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); }
@Test public void testGetDiffId_corrupted() { try { TEST_CACHE_STORAGE_FILES.getDigestFromFilename(Paths.get("not long enough")); Assert.fail("Should have thrown CacheCorruptedException"); } catch (CacheCorruptedException ex) { MatcherAssert.assertThat( ex.getMessage(), CoreMatchers.startsWith("Layer file did not include valid hash: not long enough")); MatcherAssert.assertThat(ex.getCause(), CoreMatchers.instanceOf(DigestException.class)); } try { TEST_CACHE_STORAGE_FILES.getDigestFromFilename( Paths.get( "not valid hash bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); Assert.fail("Should have thrown CacheCorruptedException"); } catch (CacheCorruptedException ex) { MatcherAssert.assertThat( ex.getMessage(), CoreMatchers.startsWith( "Layer file did not include valid hash: " + "not valid hash bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); MatcherAssert.assertThat(ex.getCause(), CoreMatchers.instanceOf(DigestException.class)); } }