Skip to content

Commit 58909e8

Browse files
committed
Better test name
Longer lines
1 parent 70ad75d commit 58909e8

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,30 @@ private String showFailures() {
9090

9191
@AfterEach
9292
public void tearDown() {
93-
9493
// reset file cleaner class, so as not to break other tests
95-
9694
/**
97-
* The following block of code can possibly be removed when the deprecated {@link FileCleaner} is gone. The
98-
* question is, whether we want to support reuse of {@link FileCleaningTracker} instances, which we should, IMO,
99-
* not.
95+
* The following block of code can possibly be removed when the deprecated {@link FileCleaner} is gone. The question is, whether we want to support
96+
* reuse of {@link FileCleaningTracker} instances, which we should, IMO, not.
10097
*/
10198
{
10299
if (fileCleaningTracker != null) {
100+
if (fileCleaningTracker.reaper != null) {
101+
fileCleaningTracker.reaper.interrupt();
102+
}
103103
fileCleaningTracker.refQueue = new ReferenceQueue<>();
104104
fileCleaningTracker.trackers.clear();
105105
fileCleaningTracker.deleteFailures.clear();
106106
fileCleaningTracker.exitWhenFinished = false;
107107
fileCleaningTracker.reaper = null;
108108
}
109109
}
110-
111110
fileCleaningTracker = null;
112111
}
113112

114113
@Test
115114
void testFileCleanerDirectory_ForceStrategy_FileSource() throws Exception {
116115
if (!testFile.getParentFile().exists()) {
117-
throw new IOException("Cannot create file " + testFile
118-
+ " as the parent directory does not exist");
116+
throw new IOException("Cannot create file " + testFile + " as the parent directory does not exist");
119117
}
120118
try (BufferedOutputStream output =
121119
new BufferedOutputStream(Files.newOutputStream(testFile.toPath()))) {
@@ -131,7 +129,7 @@ void testFileCleanerDirectory_ForceStrategy_FileSource() throws Exception {
131129

132130
obj = null;
133131

134-
waitUntilTrackCount();
132+
waitUntilTrackCount0();
135133
pauseForDeleteToComplete(testFile.getParentFile());
136134

137135
assertEquals(0, fileCleaningTracker.getTrackCount());
@@ -142,8 +140,7 @@ void testFileCleanerDirectory_ForceStrategy_FileSource() throws Exception {
142140
@Test
143141
void testFileCleanerDirectory_ForceStrategy_PathSource() throws Exception {
144142
if (!Files.exists(testPath.getParent())) {
145-
throw new IOException("Cannot create file " + testPath
146-
+ " as the parent directory does not exist");
143+
throw new IOException("Cannot create file " + testPath + " as the parent directory does not exist");
147144
}
148145
try (BufferedOutputStream output =
149146
new BufferedOutputStream(Files.newOutputStream(testPath))) {
@@ -159,7 +156,7 @@ void testFileCleanerDirectory_ForceStrategy_PathSource() throws Exception {
159156

160157
obj = null;
161158

162-
waitUntilTrackCount();
159+
waitUntilTrackCount0();
163160
pauseForDeleteToComplete(testPath.getParent());
164161

165162
assertEquals(0, fileCleaningTracker.getTrackCount());
@@ -180,7 +177,7 @@ void testFileCleanerDirectory_NullStrategy() throws Exception {
180177

181178
obj = null;
182179

183-
waitUntilTrackCount();
180+
waitUntilTrackCount0();
184181

185182
assertEquals(0, fileCleaningTracker.getTrackCount());
186183
assertTrue(testFile.exists()); // not deleted, as dir not empty
@@ -200,7 +197,7 @@ void testFileCleanerDirectoryFileSource() throws Exception {
200197

201198
obj = null;
202199

203-
waitUntilTrackCount();
200+
waitUntilTrackCount0();
204201

205202
assertEquals(0, fileCleaningTracker.getTrackCount());
206203
assertTrue(testFile.exists()); // not deleted, as dir not empty
@@ -220,7 +217,7 @@ void testFileCleanerDirectoryPathSource() throws Exception {
220217

221218
obj = null;
222219

223-
waitUntilTrackCount();
220+
waitUntilTrackCount0();
224221

225222
assertEquals(0, fileCleaningTracker.getTrackCount());
226223
assertTrue(Files.exists(testPath)); // not deleted, as dir not empty
@@ -267,7 +264,7 @@ void testFileCleanerExitWhenFinished1() throws Exception {
267264
testFile = null;
268265
raf = null;
269266

270-
waitUntilTrackCount();
267+
waitUntilTrackCount0();
271268
pauseForDeleteToComplete(new File(path));
272269

273270
assertEquals(0, fileCleaningTracker.getTrackCount(), "10-Track Count");
@@ -294,7 +291,7 @@ void testFileCleanerExitWhenFinished2() throws Exception {
294291
testFile = null;
295292
r = null;
296293

297-
waitUntilTrackCount();
294+
waitUntilTrackCount0();
298295
pauseForDeleteToComplete(new File(path));
299296

300297
assertEquals(0, fileCleaningTracker.getTrackCount());
@@ -318,7 +315,7 @@ void testFileCleanerExitWhenFinishedFirst() throws Exception {
318315
assertTrue(fileCleaningTracker.exitWhenFinished);
319316
assertNull(fileCleaningTracker.reaper);
320317

321-
waitUntilTrackCount();
318+
waitUntilTrackCount0();
322319

323320
assertEquals(0, fileCleaningTracker.getTrackCount());
324321
assertTrue(fileCleaningTracker.exitWhenFinished);
@@ -341,7 +338,7 @@ void testFileCleanerFile() throws Exception {
341338
testFile = null;
342339
raf = null;
343340

344-
waitUntilTrackCount();
341+
waitUntilTrackCount0();
345342
pauseForDeleteToComplete(new File(path));
346343

347344
assertEquals(0, fileCleaningTracker.getTrackCount());
@@ -355,7 +352,7 @@ void testFileCleanerNull() {
355352
assertThrows(NullPointerException.class, () -> fileCleaningTracker.track((String) null, new Object(), FileDeleteStrategy.NORMAL));
356353
}
357354

358-
private void waitUntilTrackCount() throws Exception {
355+
private void waitUntilTrackCount0() throws Exception {
359356
System.gc();
360357
TestUtils.sleep(500);
361358
int count = 0;
@@ -365,8 +362,8 @@ private void waitUntilTrackCount() throws Exception {
365362
long i = 0;
366363
while (fileCleaningTracker.getTrackCount() != 0) {
367364
list.add(
368-
"A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String "
369-
+ i++);
365+
"A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String "
366+
+ i++);
370367
}
371368
} catch (final Throwable ignored) {
372369
}
@@ -377,6 +374,5 @@ private void waitUntilTrackCount() throws Exception {
377374
if (fileCleaningTracker.getTrackCount() != 0) {
378375
throw new IllegalStateException("Your JVM is not releasing References, try running the test with less memory (-Xmx)");
379376
}
380-
381377
}
382378
}

0 commit comments

Comments
 (0)