Reuse AbstractTempDirTest
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 6383f64..c3b71f6 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 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 @@
@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 @@
@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 @@
*/
@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 @@
*/
@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 @@
@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 @@
}
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 @@
@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 @@
PathUtils.setReadOnly(resolved, false);
PathUtils.deleteFile(resolved);
// This will throw if not empty.
- Files.deleteIfExists(tempDir);
+ Files.deleteIfExists(tempDirPath);
}
}