Move test data removal logic to instance method

This commit is contained in:
Ivan Vilata-i-Balaguer 2016-04-27 13:32:45 +02:00
parent e12d61d026
commit b02c5bf2be

View file

@ -140,9 +140,9 @@ public class NetworkStressTest {
// Wait for concurrent tasks to finish. // Wait for concurrent tasks to finish.
shutdownLatch.await(); shutdownLatch.await();
// Cleanup directory if not given explicitly. // Cleanup temporary directory.
if (tempDir != null && System.getenv(TEST_DIR_ENVVAR) == null) { if (tempDir != null) {
deleteRecursively(tempDir); deleteTempDirectory();
} }
} }
@ -173,9 +173,11 @@ public class NetworkStressTest {
return stressTestDirPath; return stressTestDirPath;
} }
private static void deleteRecursively(@NotNull final Path path) throws IOException { private void deleteTempDirectory() throws IOException {
// Based on <https://stackoverflow.com/a/27917071/6239236> by Tomasz Dzięcielewski. // Based on <https://stackoverflow.com/a/27917071/6239236> by Tomasz Dzięcielewski.
Files.walkFileTree(path, new SimpleFileVisitor<Path>() { if (System.getenv(TEST_DIR_ENVVAR) != null)
return; // do not remove if given explicitly
Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file); Files.delete(file);