|
16 | 16 | */ |
17 | 17 | package org.apache.commons.io; |
18 | 18 |
|
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; |
24 | 23 |
|
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; |
26 | 29 | import java.lang.ref.ReferenceQueue; |
27 | 30 | import java.util.ArrayList; |
28 | 31 | import java.util.List; |
29 | 32 |
|
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; |
34 | 39 |
|
35 | 40 | /** |
36 | 41 | * This is used to test {@link FileCleaningTracker} for correctness. |
37 | 42 | * |
38 | 43 | * @see FileCleaningTracker |
39 | 44 | */ |
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 | + |
41 | 54 | protected FileCleaningTracker newInstance() { |
42 | 55 | return new FileCleaningTracker(); |
43 | 56 | } |
44 | 57 |
|
45 | 58 | private File testFile; |
46 | 59 | private FileCleaningTracker theInstance; |
47 | 60 |
|
48 | | - public FileCleaningTrackerTestCase() { |
49 | | - testFile = new File(getTestDirectory(), "file-test.txt"); |
50 | | - } |
51 | | - |
52 | 61 | @Before |
53 | 62 | public void setUp() throws Exception { |
| 63 | + testFile = new File(getTestDirectory(), "file-test.txt"); |
54 | 64 | theInstance = newInstance(); |
55 | | - getTestDirectory(); |
56 | 65 | } |
57 | 66 |
|
58 | 67 | @After |
59 | 68 | public void tearDown() throws Exception { |
60 | | - FileUtils.deleteDirectory(getTestDirectory()); |
61 | 69 |
|
62 | 70 | // reset file cleaner class, so as not to break other tests |
63 | 71 |
|
64 | 72 | /** |
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. |
69 | 76 | */ |
70 | 77 | { |
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 | + } |
76 | 85 | } |
77 | 86 |
|
78 | 87 | theInstance = null; |
@@ -235,7 +244,7 @@ public void testFileCleanerExitWhenFinished_NoTrackAfter() throws Exception { |
235 | 244 | public void testFileCleanerExitWhenFinished1() throws Exception { |
236 | 245 | final String path = testFile.getPath(); |
237 | 246 |
|
238 | | - assertEquals("1-testFile exists", false, testFile.exists()); |
| 247 | + assertEquals("1-testFile exists: " + testFile, false, testFile.exists()); |
239 | 248 | RandomAccessFile r = new RandomAccessFile(testFile, "rw"); |
240 | 249 | assertEquals("2-testFile exists", true, testFile.exists()); |
241 | 250 |
|
|
0 commit comments