FileAlterationMonitorTestCase and FileAlterationObserverTestCase: use TemporaryFolder rule, so that tests are independent
MODIFY
src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java
src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java
import org.apache.commons.io.filefilter.HiddenFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
/**
* {@link FileAlterationObserver} Test Case.
*/
public abstract class AbstractMonitorTestCase {
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
/** File observer */
protected FileAlterationObserver observer;
/** Listener which collects file changes */
protected CollectionFileListener listener;
- /** Test directory name */
- protected String testDirName = null;
-
/** Directory for test files */
protected File testDir;
@Before
public void setUp() throws Exception {
- testDir = new File(new File("."), testDirName);
- if (testDir.exists()) {
- FileUtils.cleanDirectory(testDir);
- } else {
- testDir.mkdir();
- }
+ testDir = temporaryFolder.getRoot();
final IOFileFilter files = FileFilterUtils.fileFileFilter();
final IOFileFilter javaSuffix = FileFilterUtils.suffixFileFilter(".java");

MODIFY
src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
*
*/
public FileAlterationMonitorTestCase() {
- testDirName = "test-monitor";
listener = new CollectionFileListener(false);
}

MODIFY
src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
*
*/
public FileAlterationObserverTestCase() {
- testDirName = "test-observer";
listener = new CollectionFileListener(true);
}

FileAlterationMonitorTestCase and FileAlterationObserverTestCase: use TemporaryFolder rule, so that tests are independent