diff --git a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java index f787fdacb3..1e4d729982 100644 --- a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java +++ b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java @@ -140,9 +140,9 @@ public class NetworkStressTest { // Wait for concurrent tasks to finish. shutdownLatch.await(); - // Cleanup directory if not given explicitly. - if (tempDir != null && System.getenv(TEST_DIR_ENVVAR) == null) { - deleteRecursively(tempDir); + // Cleanup temporary directory. + if (tempDir != null) { + deleteTempDirectory(); } } @@ -173,9 +173,11 @@ public class NetworkStressTest { return stressTestDirPath; } - private static void deleteRecursively(@NotNull final Path path) throws IOException { + private void deleteTempDirectory() throws IOException { // Based on by Tomasz Dzięcielewski. - Files.walkFileTree(path, new SimpleFileVisitor() { + if (System.getenv(TEST_DIR_ENVVAR) != null) + return; // do not remove if given explicitly + Files.walkFileTree(tempDir, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file);