You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/13 14:59:36 UTC

[commons-io] branch master updated: Test: Do NOT used a try-with-resources statement here or the test will fail.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 37ce4d5b Test: Do NOT used a try-with-resources statement here or the test will fail.
37ce4d5b is described below

commit 37ce4d5b702285b1c5178ff0256a01a5f937c6d1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jun 13 10:59:32 2023 -0400

    Test: Do NOT used a try-with-resources statement here or the test will
    fail.
---
 .../apache/commons/io/FileCleaningTrackerTest.java | 111 +++++++++++----------
 1 file changed, 57 insertions(+), 54 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java b/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java
index 01c9d35d..a534670c 100644
--- a/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java
+++ b/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java
@@ -111,6 +111,46 @@ public class FileCleaningTrackerTest extends AbstractTempDirTest {
         theInstance = null;
     }
 
+    @Test
+    public void testFileCleanerDirectoryFileSource() throws Exception {
+        TestUtils.createFile(testFile, 100);
+        assertTrue(testFile.exists());
+        assertTrue(tempDirFile.exists());
+
+        Object obj = new Object();
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(tempDirFile, obj);
+        assertEquals(1, theInstance.getTrackCount());
+
+        obj = null;
+
+        waitUntilTrackCount();
+
+        assertEquals(0, theInstance.getTrackCount());
+        assertTrue(testFile.exists());  // not deleted, as dir not empty
+        assertTrue(testFile.getParentFile().exists());  // not deleted, as dir not empty
+    }
+
+    @Test
+    public void testFileCleanerDirectoryPathSource() throws Exception {
+        TestUtils.createFile(testPath, 100);
+        assertTrue(Files.exists(testPath));
+        assertTrue(Files.exists(tempDirPath));
+
+        Object obj = new Object();
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(tempDirPath, obj);
+        assertEquals(1, theInstance.getTrackCount());
+
+        obj = null;
+
+        waitUntilTrackCount();
+
+        assertEquals(0, theInstance.getTrackCount());
+        assertTrue(Files.exists(testPath));  // not deleted, as dir not empty
+        assertTrue(Files.exists(testPath.getParent()));  // not deleted, as dir not empty
+    }
+
     @Test
     public void testFileCleanerDirectory_ForceStrategy_FileSource() throws Exception {
         if (!testFile.getParentFile().exists()) {
@@ -187,46 +227,6 @@ public class FileCleaningTrackerTest extends AbstractTempDirTest {
         assertTrue(testFile.getParentFile().exists());  // not deleted, as dir not empty
     }
 
-    @Test
-    public void testFileCleanerDirectoryFileSource() throws Exception {
-        TestUtils.createFile(testFile, 100);
-        assertTrue(testFile.exists());
-        assertTrue(tempDirFile.exists());
-
-        Object obj = new Object();
-        assertEquals(0, theInstance.getTrackCount());
-        theInstance.track(tempDirFile, obj);
-        assertEquals(1, theInstance.getTrackCount());
-
-        obj = null;
-
-        waitUntilTrackCount();
-
-        assertEquals(0, theInstance.getTrackCount());
-        assertTrue(testFile.exists());  // not deleted, as dir not empty
-        assertTrue(testFile.getParentFile().exists());  // not deleted, as dir not empty
-    }
-
-    @Test
-    public void testFileCleanerDirectoryPathSource() throws Exception {
-        TestUtils.createFile(testPath, 100);
-        assertTrue(Files.exists(testPath));
-        assertTrue(Files.exists(tempDirPath));
-
-        Object obj = new Object();
-        assertEquals(0, theInstance.getTrackCount());
-        theInstance.track(tempDirPath, obj);
-        assertEquals(1, theInstance.getTrackCount());
-
-        obj = null;
-
-        waitUntilTrackCount();
-
-        assertEquals(0, theInstance.getTrackCount());
-        assertTrue(Files.exists(testPath));  // not deleted, as dir not empty
-        assertTrue(Files.exists(testPath.getParent()));  // not deleted, as dir not empty
-    }
-
     @Test
     public void testFileCleanerExitWhenFinished_NoTrackAfter() {
         assertFalse(theInstance.exitWhenFinished);
@@ -247,22 +247,25 @@ public class FileCleaningTrackerTest extends AbstractTempDirTest {
         final String path = testFile.getPath();
 
         assertFalse(testFile.exists(), "1-testFile exists: " + testFile);
-        try (RandomAccessFile raf = createRandomAccessFile()) {
-            assertTrue(testFile.exists(), "2-testFile exists");
-
-            assertEquals(0, theInstance.getTrackCount(), "3-Track Count");
-            theInstance.track(path, raf);
-            assertEquals(1, theInstance.getTrackCount(), "4-Track Count");
-            assertFalse(theInstance.exitWhenFinished, "5-exitWhenFinished");
-            assertTrue(theInstance.reaper.isAlive(), "6-reaper.isAlive");
-
-            assertFalse(theInstance.exitWhenFinished, "7-exitWhenFinished");
-            theInstance.exitWhenFinished();
-            assertTrue(theInstance.exitWhenFinished, "8-exitWhenFinished");
-            assertTrue(theInstance.reaper.isAlive(), "9-reaper.isAlive");
+        
+        // Do NOT used a try-with-resources statement here or the test will fail.
+        RandomAccessFile raf = createRandomAccessFile();
+        assertTrue(testFile.exists(), "2-testFile exists");
+
+        assertEquals(0, theInstance.getTrackCount(), "3-Track Count");
+        theInstance.track(path, raf);
+        assertEquals(1, theInstance.getTrackCount(), "4-Track Count");
+        assertFalse(theInstance.exitWhenFinished, "5-exitWhenFinished");
+        assertTrue(theInstance.reaper.isAlive(), "6-reaper.isAlive");
+
+        assertFalse(theInstance.exitWhenFinished, "7-exitWhenFinished");
+        theInstance.exitWhenFinished();
+        assertTrue(theInstance.exitWhenFinished, "8-exitWhenFinished");
+        assertTrue(theInstance.reaper.isAlive(), "9-reaper.isAlive");
 
-        }
+        raf.close();
         testFile = null;
+        raf = null;
 
         waitUntilTrackCount();
         pauseForDeleteToComplete(new File(path));