### Question:
FileSystemUtil { static boolean deleteParentDirectoriesIfEmpty(FileSystem fs, Path root, Path path) throws IOException { boolean deleted = false; try { for (Path current = path.getParent(); !current.equals(root) && !(current.getParent() == null); current = current.getParent()) { final FileStatus[] stats = fs.listStatus(current); if (stats == null || stats.length == 0) { LOG.debug("Deleting empty path {}", current); deleted = fs.delete(current, true) || deleted; } else { break; } } } catch (FileNotFoundException e) { LOG.debug("Path does not exist it may have been deleted by another process.", e); } return deleted; }  static void ensureLocationExists(
      DatasetDescriptor descriptor, Configuration conf); static Schema schema(String name, FileSystem fs, Path location); static PartitionStrategy strategy(FileSystem fs, Path location); static Format format(FileSystem fs, Path location); static Collection<DatasetDescriptor> findPotentialDatasets(
      FileSystem fs, Path path); static boolean supportsRename(URI fsUri, Configuration conf);  }### Answer:
@Test public void testDeleteParentDirectoriesIfEmptyCatchesFileNotFoundException() throws Exception { FileSystem fs = mock(FileSystem.class); Path root = mock(Path.class); Path path = mock(Path.class); Path firstParent = mock(Path.class); when(path.getParent()).thenReturn(firstParent); when(firstParent.getParent()).thenReturn(root); when(fs.listStatus(firstParent)).thenThrow(FileNotFoundException.class); boolean pathDeleted = FileSystemUtil.deleteParentDirectoriesIfEmpty(fs, root, path); verify(fs).listStatus(firstParent); assertFalse(pathDeleted); }
@Test public void testDeleteParentDirectoriesIfEmpty() throws Exception { Path root = new Path(temp.getRoot().toURI() + "/"); File subFolder = temp.newFolder("subFolder"); File subSubFolder = new File(subFolder, "subSubFolder"); Path subSubFolderPath = new Path(subSubFolder.toURI()); FileSystem fs = LocalFileSystem.getInstance(); boolean pathDeleted = FileSystemUtil.deleteParentDirectoriesIfEmpty(fs, root, subSubFolderPath); assertTrue(pathDeleted); assertFalse(subFolder.exists()); assertTrue(temp.getRoot().exists()); }