/** * Deletes all files associated with given {@link StorageData}, thus completely removes storage * from disk. * * @param storageData * Storage to delete data for. * @throws IOException * If {@link IOException} happens. */ protected void deleteCompleteStorageDataFromDisk(IStorageData storageData) throws IOException { Path storageDir = getStoragePath(storageData); if (log.isDebugEnabled()) { log.info("Deleting the complete storage data from disk. Path: " + storageDir); } if (Files.exists(storageDir)) { Files.walkFileTree(storageDir, new DeleteFileVisitor()); } }
/** * Clean test folder after each test. */ @AfterMethod public void cleanUp() throws IOException { if (Files.exists(Paths.get(TEST_FOLDER))) { Files.walkFileTree(Paths.get(TEST_FOLDER), new DeleteFileVisitor()); Files.deleteIfExists(Paths.get(TEST_FOLDER)); } } }
/** * Clean test folder after each test. */ @AfterMethod public void cleanUp() throws IOException { if (Files.exists(Paths.get(TEST_FOLDER))) { Files.walkFileTree(Paths.get(TEST_FOLDER), new DeleteFileVisitor()); Files.deleteIfExists(Paths.get(TEST_FOLDER)); } }
@AfterTest public void cleanUp() throws IOException { if (Files.exists(testPath)) { Files.walkFileTree(testPath, new DeleteFileVisitor()); } Files.deleteIfExists(testPath); }
/** * Test that deleting of directory and it content works, but that the parent dir won't be * touched. */ @Test public void deleteFileVisitor() throws IOException { // we create additional dir and file in that dir Path dir = testPath.resolve("dir"); Files.createDirectories(dir); Path file = dir.resolve(".testFile"); Files.createFile(file); Files.walkFileTree(dir, new DeleteFileVisitor()); assertThat(Files.exists(file), is(false)); assertThat(Files.exists(dir), is(false)); assertThat(Files.exists(testPath), is(true)); }
Files.walkFileTree(parentDir, new DeleteFileVisitor());