From b443d4c82084f6afbafc05873cb4df0208bad57c Mon Sep 17 00:00:00 2001 From: jakubs <jakubs> Date: Fri, 15 Jun 2012 08:55:21 +0000 Subject: [PATCH] BIS-21 SP-107 refactor AbstractFileSystemTestCase SVN: 25725 --- .../tests/AbstractFileSystemTestCase.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/base/source/java/ch/systemsx/cisd/base/tests/AbstractFileSystemTestCase.java b/base/source/java/ch/systemsx/cisd/base/tests/AbstractFileSystemTestCase.java index badc0ae305a..b91323b1674 100644 --- a/base/source/java/ch/systemsx/cisd/base/tests/AbstractFileSystemTestCase.java +++ b/base/source/java/ch/systemsx/cisd/base/tests/AbstractFileSystemTestCase.java @@ -40,7 +40,7 @@ public abstract class AbstractFileSystemTestCase extends AssertJUnit protected static final String TARGETS_DIRECTORY = "targets"; - private static final File UNIT_TEST_ROOT_DIRECTORY = new File(TARGETS_DIRECTORY + protected static final File UNIT_TEST_ROOT_DIRECTORY = new File(TARGETS_DIRECTORY + File.separator + UNIT_TEST_WORKING_DIRECTORY); protected final File workingDirectory; @@ -70,21 +70,37 @@ public abstract class AbstractFileSystemTestCase extends AssertJUnit return file; } - private final File createWorkingDirectory() + /** + * Creates a directory in the unit test root directory "targets/unit-test-wd" + */ + protected final File createDirectoryInUnitTestRoot(String dirName) { - final File directory = new File(UNIT_TEST_ROOT_DIRECTORY, getClass().getName()); + final File directory = new File(UNIT_TEST_ROOT_DIRECTORY, dirName); directory.mkdirs(); directory.deleteOnExit(); return directory; } + private final File createWorkingDirectory() + { + return createDirectoryInUnitTestRoot(getClass().getName()); + } + @BeforeMethod public void setUp() throws IOException { - deleteDirectory(workingDirectory); - workingDirectory.mkdirs(); - assertEquals(true, workingDirectory.isDirectory()); - File[] files = workingDirectory.listFiles(); + cleanUpDirectoryBeforeTheTest(workingDirectory); + } + + /** + * Deletes, recreates and verifies that this is the empty directory + */ + protected void cleanUpDirectoryBeforeTheTest(File directory) + { + deleteDirectory(directory); + directory.mkdirs(); + assertEquals(true, directory.isDirectory()); + File[] files = directory.listFiles(); if (files != null) { assertEquals("Unexpected files " + Arrays.asList(files), 0, files.length); -- GitLab