From b02c5bf2be6a0db33244bedf443404aeb1d88401 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 27 Apr 2016 13:32:45 +0200 Subject: [PATCH] Move test data removal logic to instance method --- .../io/bitsquare/p2p/network/NetworkStressTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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);