/** Test that an empty dir will be removed during cleaning. */
 @Test
 public void testCleanEmptyParentDir() throws Exception {
   File emptyGrandParent = new File(rootDir, "ae");
   emptyGrandParent.mkdir();
   File emptyParent = new File(emptyGrandParent, "ffacd15b0f66d5081a93407d3ff5e3c65a71");
   emptyParent.mkdir();
   assertThat(emptyGrandParent.exists(), is(true));
   assertThat(emptyParent.exists(), is(true));
   Map<String, Set<String>> result =
       repository.cleanObsoleteContent(); // To mark content for deletion
   assertThat(result.get(ContentRepository.MARKED_CONTENT).size(), is(1));
   assertThat(result.get(ContentRepository.DELETED_CONTENT).size(), is(0));
   assertThat(
       result.get(ContentRepository.MARKED_CONTENT).contains(emptyParent.getAbsolutePath()),
       is(true));
   Thread.sleep(10);
   result = repository.cleanObsoleteContent();
   assertThat(emptyGrandParent.exists(), is(false));
   assertThat(emptyParent.exists(), is(false));
   assertThat(result.get(ContentRepository.MARKED_CONTENT).size(), is(0));
   assertThat(result.get(ContentRepository.DELETED_CONTENT).size(), is(1));
   assertThat(
       result.get(ContentRepository.DELETED_CONTENT).contains(emptyParent.getAbsolutePath()),
       is(true));
 }
 /**
  * Test that an empty dir with a system metadata file .DS_Store will be removed during cleaning.
  */
 @Test
 public void testCleanEmptyParentDirWithSystemMetaDataFile() throws Exception {
   File emptyGrandParent = new File(rootDir, "ae");
   emptyGrandParent.mkdir();
   File metaDataFile = new File(emptyGrandParent, ".DS_Store");
   metaDataFile.createNewFile();
   assertThat(emptyGrandParent.exists(), is(true));
   assertThat(metaDataFile.exists(), is(true));
   Map<String, Set<String>> result =
       repository.cleanObsoleteContent(); // To mark content for deletion
   assertThat(result.get(ContentRepository.MARKED_CONTENT).size(), is(1));
   assertThat(result.get(ContentRepository.DELETED_CONTENT).size(), is(0));
   assertThat(
       result.get(ContentRepository.MARKED_CONTENT).contains(metaDataFile.getAbsolutePath()),
       is(true));
   Thread.sleep(10);
   result = repository.cleanObsoleteContent();
   assertThat(emptyGrandParent.exists(), is(false));
   assertThat(metaDataFile.exists(), is(false));
   assertThat(result.get(ContentRepository.MARKED_CONTENT).size(), is(0));
   assertThat(result.get(ContentRepository.DELETED_CONTENT).size(), is(1));
   assertThat(
       result.get(ContentRepository.DELETED_CONTENT).contains(metaDataFile.getAbsolutePath()),
       is(true));
 }
 /** Test that an dir not empty with no content will not be removed during cleaning. */
 @Test
 public void testNotEmptyDir() throws Exception {
   Path parentDir = rootDir.toPath().resolve("ae").resolve("ffacd15b0f66d5081a93407d3ff5e3c65a71");
   Path overlay = parentDir.resolve("overlay.xhtml");
   Path content = parentDir.resolve("content");
   Files.createDirectories(overlay.getParent());
   try (InputStream stream = getResourceAsStream("overlay.xhtml")) {
     Files.copy(stream, overlay);
     Files.copy(overlay, content);
     assertThat(Files.exists(content), is(true));
     assertThat(Files.exists(overlay), is(true));
     Map<String, Set<String>> result =
         repository.cleanObsoleteContent(); // Mark content for deletion
     assertThat(result.get(ContentRepository.MARKED_CONTENT).size(), is(1));
     assertThat(result.get(ContentRepository.DELETED_CONTENT).size(), is(0));
     assertThat(
         result
             .get(ContentRepository.MARKED_CONTENT)
             .contains(parentDir.toFile().getAbsolutePath()),
         is(true));
     Thread.sleep(10);
     result = repository.cleanObsoleteContent();
     assertThat(Files.exists(content), is(false));
     assertThat(Files.exists(overlay), is(true));
     assertThat(result.get(ContentRepository.MARKED_CONTENT).size(), is(0));
     assertThat(result.get(ContentRepository.DELETED_CONTENT).size(), is(1));
     assertThat(
         result
             .get(ContentRepository.DELETED_CONTENT)
             .contains(parentDir.toFile().getAbsolutePath()),
         is(true));
   } finally {
     Files.deleteIfExists(overlay);
     Files.deleteIfExists(overlay.getParent());
     Files.deleteIfExists(overlay.getParent().getParent());
   }
 }