@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); }
: fs.delete(absolute, true /* include any files */); deleted |= deleteParentDirectoriesIfEmpty(fs, root, absolute);
@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()); }