### Question:
LayerEntriesSelector { static DescriptorDigest generateSelector(ImmutableList<FileEntry> layerEntries) throws IOException { return Digests.computeJsonDigest(toSortedJsonTemplates(layerEntries)); } private  LayerEntriesSelector();   }### Answer:
@Test public void testGenerateSelector_empty() throws IOException { DescriptorDigest expectedSelector = Digests.computeJsonDigest(ImmutableList.of()); Assert.assertEquals( expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of())); }
@Test public void testGenerateSelector() throws IOException { DescriptorDigest expectedSelector = Digests.computeJsonDigest(toLayerEntryTemplates(inOrderLayerEntries)); Assert.assertEquals( expectedSelector, LayerEntriesSelector.generateSelector(outOfOrderLayerEntries)); }
@Test public void testGenerateSelector_sourceModificationTimeChanged() throws IOException { Path layerFile = temporaryFolder.newFile().toPath(); Files.setLastModifiedTime(layerFile, FileTime.from(Instant.EPOCH)); FileEntry layerEntry = defaultLayerEntry(layerFile, AbsoluteUnixPath.get("/extraction/path")); DescriptorDigest expectedSelector = LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry)); Files.setLastModifiedTime(layerFile, FileTime.from(Instant.ofEpochSecond(1))); Assert.assertNotEquals( expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry))); Files.setLastModifiedTime(layerFile, FileTime.from(Instant.EPOCH)); Assert.assertEquals( expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry))); }
@Test public void testGenerateSelector_targetModificationTimeChanged() throws IOException { Path layerFile = temporaryFolder.newFile().toPath(); AbsoluteUnixPath pathInContainer = AbsoluteUnixPath.get("/bar"); FilePermissions permissions = FilePermissions.fromOctalString("111"); FileEntry layerEntry1 = new FileEntry(layerFile, pathInContainer, permissions, Instant.now()); FileEntry layerEntry2 = new FileEntry(layerFile, pathInContainer, permissions, Instant.EPOCH); Assert.assertNotEquals( LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry1)), LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry2))); }
@Test public void testGenerateSelector_permissionsModified() throws IOException { Path layerFile = temporaryFolder.newFolder("testFolder").toPath().resolve("file"); Files.write(layerFile, "hello".getBytes(StandardCharsets.UTF_8)); FileEntry layerEntry111 = new FileEntry( layerFile, AbsoluteUnixPath.get("/extraction/path"), FilePermissions.fromOctalString("111"), FileEntriesLayer.DEFAULT_MODIFICATION_TIME); FileEntry layerEntry222 = new FileEntry( layerFile, AbsoluteUnixPath.get("/extraction/path"), FilePermissions.fromOctalString("222"), FileEntriesLayer.DEFAULT_MODIFICATION_TIME); Assert.assertNotEquals( LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry111)), LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry222))); }
@Test public void testGenerateSelector_ownersModified() throws IOException { Path layerFile = temporaryFolder.newFolder("testFolder").toPath().resolve("file"); Files.write(layerFile, "hello".getBytes(StandardCharsets.UTF_8)); FileEntry layerEntry111 = new FileEntry( layerFile, AbsoluteUnixPath.get("/extraction/path"), FilePermissions.fromOctalString("111"), FileEntriesLayer.DEFAULT_MODIFICATION_TIME, "0:0"); FileEntry layerEntry222 = new FileEntry( layerFile, AbsoluteUnixPath.get("/extraction/path"), FilePermissions.fromOctalString("222"), FileEntriesLayer.DEFAULT_MODIFICATION_TIME, "foouser"); Assert.assertNotEquals( LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry111)), LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry222))); }