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 39fd7bc98 Reuse AbstractTempDirTest
39fd7bc98 is described below

commit 39fd7bc988b36f49c1164480bbfa88c26bd9cd4e
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Apr 4 06:47:19 2024 -0400

    Reuse AbstractTempDirTest
---
 .../commons/io/file/PathUtilsDeleteFileTest.java   | 59 +++++++---------------
 1 file changed, 19 insertions(+), 40 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java 
b/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java
index 6383f646e..c3b71f6dd 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java
@@ -32,44 +32,23 @@ import java.nio.file.Paths;
 
 import org.apache.commons.io.file.Counters.PathCounters;
 import org.apache.commons.lang3.SystemUtils;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /**
  * Tests {@link DeletingPathVisitor}.
  */
-public class PathUtilsDeleteFileTest {
-
-    private Path tempDir;
-
-    @AfterEach
-    public void afterEach() throws IOException {
-        // backstop
-        if (Files.exists(tempDir) && PathUtils.isEmptyDirectory(tempDir)) {
-            Files.deleteIfExists(tempDir);
-        }
-    }
-
-    @BeforeEach
-    public void beforeEach() throws IOException {
-        tempDir = Files.createTempDirectory(getClass().getCanonicalName());
-    }
+public class PathUtilsDeleteFileTest extends AbstractTempDirTest {
 
     @Test
     public void testDeleteBrokenLink() throws IOException {
         assumeFalse(SystemUtils.IS_OS_WINDOWS);
-
-        final Path missingFile = tempDir.resolve("missing.txt");
-        final Path brokenLink = tempDir.resolve("broken.txt");
+        final Path missingFile = tempDirPath.resolve("missing.txt");
+        final Path brokenLink = tempDirPath.resolve("broken.txt");
         Files.createSymbolicLink(brokenLink, missingFile);
-
         assertTrue(Files.exists(brokenLink, LinkOption.NOFOLLOW_LINKS));
         assertFalse(Files.exists(missingFile, LinkOption.NOFOLLOW_LINKS));
-
         PathUtils.deleteFile(brokenLink);
-
         assertFalse(Files.exists(brokenLink, LinkOption.NOFOLLOW_LINKS), 
"Symbolic link not removed");
     }
 
@@ -79,10 +58,10 @@ public class PathUtilsDeleteFileTest {
     @Test
     public void testDeleteFileDirectory1FileSize0() throws IOException {
         final String fileName = "file-size-0.bin";
-        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0/"
 + fileName), tempDir);
-        assertCounts(0, 1, 0, PathUtils.deleteFile(tempDir.resolve(fileName)));
+        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0/"
 + fileName), tempDirPath);
+        assertCounts(0, 1, 0, 
PathUtils.deleteFile(tempDirPath.resolve(fileName)));
         // This will throw if not empty.
-        Files.deleteIfExists(tempDir);
+        Files.deleteIfExists(tempDirPath);
     }
 
     /**
@@ -91,10 +70,10 @@ public class PathUtilsDeleteFileTest {
     @Test
     public void testDeleteFileDirectory1FileSize1() throws IOException {
         final String fileName = "file-size-1.bin";
-        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/"
 + fileName), tempDir);
-        assertCounts(0, 1, 1, PathUtils.deleteFile(tempDir.resolve(fileName)));
+        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/"
 + fileName), tempDirPath);
+        assertCounts(0, 1, 1, 
PathUtils.deleteFile(tempDirPath.resolve(fileName)));
         // This will throw if not empty.
-        Files.deleteIfExists(tempDir);
+        Files.deleteIfExists(tempDirPath);
     }
 
     /**
@@ -102,9 +81,9 @@ public class PathUtilsDeleteFileTest {
      */
     @Test
     public void testDeleteFileDoesNotExist() throws IOException {
-        
testDeleteFileEmpty(PathUtils.deleteFile(tempDir.resolve("file-does-not-exist.bin")));
+        
testDeleteFileEmpty(PathUtils.deleteFile(tempDirPath.resolve("file-does-not-exist.bin")));
         // This will throw if not empty.
-        Files.deleteIfExists(tempDir);
+        Files.deleteIfExists(tempDirPath);
     }
 
     private void testDeleteFileEmpty(final PathCounters pathCounts) {
@@ -116,9 +95,9 @@ public class PathUtilsDeleteFileTest {
      */
     @Test
     public void testDeleteFileEmptyDirectory() throws IOException {
-        Assertions.assertThrows(NoSuchFileException.class, () -> 
testDeleteFileEmpty(PathUtils.deleteFile(tempDir)));
+        Assertions.assertThrows(NoSuchFileException.class, () -> 
testDeleteFileEmpty(PathUtils.deleteFile(tempDirPath)));
         // This will throw if not empty.
-        Files.deleteIfExists(tempDir);
+        Files.deleteIfExists(tempDirPath);
     }
 
     /**
@@ -127,8 +106,8 @@ public class PathUtilsDeleteFileTest {
     @Test
     public void testDeleteReadOnlyFileDirectory1FileSize1() throws IOException 
{
         final String fileName = "file-size-1.bin";
-        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/"
 + fileName), tempDir);
-        final Path resolved = tempDir.resolve(fileName);
+        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/"
 + fileName), tempDirPath);
+        final Path resolved = tempDirPath.resolve(fileName);
         PathUtils.setReadOnly(resolved, true);
         if (SystemUtils.IS_OS_WINDOWS) {
             // Fails on Windows's Ubuntu subsystem.
@@ -137,7 +116,7 @@ public class PathUtilsDeleteFileTest {
         }
         assertCounts(0, 1, 1, PathUtils.deleteFile(resolved, 
StandardDeleteOption.OVERRIDE_READ_ONLY));
         // This will throw if not empty.
-        Files.deleteIfExists(tempDir);
+        Files.deleteIfExists(tempDirPath);
     }
 
     /**
@@ -146,8 +125,8 @@ public class PathUtilsDeleteFileTest {
     @Test
     public void testSetReadOnlyFileDirectory1FileSize1() throws IOException {
         final String fileName = "file-size-1.bin";
-        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/"
 + fileName), tempDir);
-        final Path resolved = tempDir.resolve(fileName);
+        
PathUtils.copyFileToDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/"
 + fileName), tempDirPath);
+        final Path resolved = tempDirPath.resolve(fileName);
         PathUtils.setReadOnly(resolved, true);
         if (SystemUtils.IS_OS_WINDOWS) {
             // Fails on Windows's Ubuntu subsystem.
@@ -157,6 +136,6 @@ public class PathUtilsDeleteFileTest {
         PathUtils.setReadOnly(resolved, false);
         PathUtils.deleteFile(resolved);
         // This will throw if not empty.
-        Files.deleteIfExists(tempDir);
+        Files.deleteIfExists(tempDirPath);
     }
 }

Reply via email to