diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/AbstractFileSystemTestCase.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/AbstractFileSystemTestCase.java index a9ffe8f0cc970d30941c7d4b9e7e161d3359a70a..1cbc4098b437204124a590ff545254f857fc4256 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/AbstractFileSystemTestCase.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/AbstractFileSystemTestCase.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod; import ch.systemsx.cisd.common.logging.LogInitializer; @@ -38,27 +39,42 @@ public abstract class AbstractFileSystemTestCase protected final File workingDirectory; + private final boolean cleanAfterMethod; + protected AbstractFileSystemTestCase() { this(true); } - protected AbstractFileSystemTestCase(final boolean deleteOnExit) + protected AbstractFileSystemTestCase(final boolean cleanAfterMethod) { - workingDirectory = new File(UNIT_TEST_ROOT_DIRECTORY, getClass().getSimpleName()); - if (deleteOnExit) - { - workingDirectory.deleteOnExit(); - } + workingDirectory = createWorkingDirectory(); LogInitializer.init(); + this.cleanAfterMethod = cleanAfterMethod; + } + + private final File createWorkingDirectory() + { + final File directory = new File(UNIT_TEST_ROOT_DIRECTORY, getClass().getSimpleName()); + directory.mkdirs(); + directory.deleteOnExit(); + return directory; } @BeforeMethod - public void setup() throws IOException + public void setUp() throws IOException { - workingDirectory.mkdirs(); FileUtils.cleanDirectory(workingDirectory); assert workingDirectory.isDirectory() && workingDirectory.listFiles().length == 0; } + @AfterClass + public void afterClass() throws IOException + { + if (cleanAfterMethod == false) + { + return; + } + FileUtils.deleteDirectory(workingDirectory); + } }