Skip to content

Commit 56c6001

Browse files
committed
Replace custom temporary folder management with JUnit's TemporaryFolder.
This will allow Maven to run tests concurrently.
1 parent 9198e94 commit 56c6001

1 file changed

Lines changed: 36 additions & 27 deletions

File tree

src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,72 @@
1616
*/
1717
package org.apache.commons.io;
1818

19-
import org.apache.commons.io.testtools.FileBasedTestCase;
20-
import org.apache.commons.io.testtools.TestUtils;
21-
import org.junit.After;
22-
import org.junit.Before;
23-
import org.junit.Test;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.fail;
2423

25-
import java.io.*;
24+
import java.io.BufferedOutputStream;
25+
import java.io.File;
26+
import java.io.FileOutputStream;
27+
import java.io.IOException;
28+
import java.io.RandomAccessFile;
2629
import java.lang.ref.ReferenceQueue;
2730
import java.util.ArrayList;
2831
import java.util.List;
2932

30-
import static org.junit.Assert.assertEquals;
31-
import static org.junit.Assert.assertFalse;
32-
import static org.junit.Assert.assertTrue;
33-
import static org.junit.Assert.fail;
33+
import org.apache.commons.io.testtools.TestUtils;
34+
import org.junit.After;
35+
import org.junit.Before;
36+
import org.junit.Rule;
37+
import org.junit.Test;
38+
import org.junit.rules.TemporaryFolder;
3439

3540
/**
3641
* This is used to test {@link FileCleaningTracker} for correctness.
3742
*
3843
* @see FileCleaningTracker
3944
*/
40-
public class FileCleaningTrackerTestCase extends FileBasedTestCase {
45+
public class FileCleaningTrackerTestCase {
46+
47+
@Rule
48+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
49+
50+
private File getTestDirectory() {
51+
return temporaryFolder.getRoot();
52+
}
53+
4154
protected FileCleaningTracker newInstance() {
4255
return new FileCleaningTracker();
4356
}
4457

4558
private File testFile;
4659
private FileCleaningTracker theInstance;
4760

48-
public FileCleaningTrackerTestCase() {
49-
testFile = new File(getTestDirectory(), "file-test.txt");
50-
}
51-
5261
@Before
5362
public void setUp() throws Exception {
63+
testFile = new File(getTestDirectory(), "file-test.txt");
5464
theInstance = newInstance();
55-
getTestDirectory();
5665
}
5766

5867
@After
5968
public void tearDown() throws Exception {
60-
FileUtils.deleteDirectory(getTestDirectory());
6169

6270
// reset file cleaner class, so as not to break other tests
6371

6472
/**
65-
* The following block of code can possibly be removed when the
66-
* deprecated {@link FileCleaner} is gone. The question is, whether
67-
* we want to support reuse of {@link FileCleaningTracker} instances,
68-
* which we should, IMO, not.
73+
* The following block of code can possibly be removed when the deprecated {@link FileCleaner} is gone. The
74+
* question is, whether we want to support reuse of {@link FileCleaningTracker} instances, which we should, IMO,
75+
* not.
6976
*/
7077
{
71-
theInstance.q = new ReferenceQueue<>();
72-
theInstance.trackers.clear();
73-
theInstance.deleteFailures.clear();
74-
theInstance.exitWhenFinished = false;
75-
theInstance.reaper = null;
78+
if (theInstance != null) {
79+
theInstance.q = new ReferenceQueue<>();
80+
theInstance.trackers.clear();
81+
theInstance.deleteFailures.clear();
82+
theInstance.exitWhenFinished = false;
83+
theInstance.reaper = null;
84+
}
7685
}
7786

7887
theInstance = null;
@@ -235,7 +244,7 @@ public void testFileCleanerExitWhenFinished_NoTrackAfter() throws Exception {
235244
public void testFileCleanerExitWhenFinished1() throws Exception {
236245
final String path = testFile.getPath();
237246

238-
assertEquals("1-testFile exists", false, testFile.exists());
247+
assertEquals("1-testFile exists: " + testFile, false, testFile.exists());
239248
RandomAccessFile r = new RandomAccessFile(testFile, "rw");
240249
assertEquals("2-testFile exists", true, testFile.exists());
241250

0 commit comments

Comments
 (0)