Reuse AbstractTempDirTest
diff --git a/src/test/java/org/apache/commons/io/file/AbstractTempDirTest.java b/src/test/java/org/apache/commons/io/file/AbstractTempDirTest.java
index b285989..38c0a34 100644
--- a/src/test/java/org/apache/commons/io/file/AbstractTempDirTest.java
+++ b/src/test/java/org/apache/commons/io/file/AbstractTempDirTest.java
@@ -32,6 +32,24 @@
public abstract class AbstractTempDirTest {
/**
+ * Creates directory test fixtures.
+ * <ol>
+ * <li>tempDirPath/subdir</li>
+ * <li>tempDirPath/symlinked-dir -> tempDirPath/subdir</li>
+ * </ol>
+ * @param rootDir Root for directory entries.
+ * @return Path to tempDirPath/subdir.
+ * @throws IOException if an I/O error occurs or the parent directory does not exist.
+ */
+ protected static Path createTempSymlinkedRelativeDir(final Path rootDir) throws IOException {
+ final Path targetDir = rootDir.resolve("subdir");
+ final Path symlinkDir = rootDir.resolve("symlinked-dir");
+ Files.createDirectory(targetDir);
+ Files.createSymbolicLink(symlinkDir, targetDir);
+ return symlinkDir;
+ }
+
+ /**
* A temporary directory managed by JUnit.
*/
@TempDir
diff --git a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java b/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java
index 800c272..8570d4a 100644
--- a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java
+++ b/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java
@@ -26,20 +26,18 @@
import org.apache.commons.io.file.Counters.PathCounters;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/**
* Tests {@link DeletingPathVisitor}.
*/
-public class DeletingPathVisitorTest extends TestArguments {
+public class DeletingPathVisitorTest extends AbstractTempDirTest {
- @TempDir
- private Path tempDir;
+ private static final String ARGS = "org.apache.commons.io.file.TestArguments#";
private void applyDeleteEmptyDirectory(final DeletingPathVisitor visitor) throws IOException {
- Files.walkFileTree(tempDir, visitor);
+ Files.walkFileTree(tempDirPath, visitor);
assertCounts(1, 0, 0, visitor);
}
@@ -47,59 +45,59 @@
* Tests an empty folder.
*/
@ParameterizedTest
- @MethodSource("deletingPathVisitors")
+ @MethodSource(ARGS + "deletingPathVisitors")
public void testDeleteEmptyDirectory(final DeletingPathVisitor visitor) throws IOException {
applyDeleteEmptyDirectory(visitor);
// This will throw if not empty.
- Files.deleteIfExists(tempDir);
+ Files.deleteIfExists(tempDirPath);
}
/**
* Tests an empty folder.
*/
@ParameterizedTest
- @MethodSource("pathCounters")
+ @MethodSource(ARGS + "pathCounters")
public void testDeleteEmptyDirectoryNullCtorArg(final PathCounters pathCounters) throws IOException {
applyDeleteEmptyDirectory(new DeletingPathVisitor(pathCounters, (String[]) null));
// This will throw if not empty.
- Files.deleteIfExists(tempDir);
+ Files.deleteIfExists(tempDirPath);
}
/**
* Tests a directory with one file of size 0.
*/
@ParameterizedTest
- @MethodSource("deletingPathVisitors")
+ @MethodSource(ARGS + "deletingPathVisitors")
public void testDeleteFolders1FileSize0(final DeletingPathVisitor visitor) throws IOException {
- PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0"), tempDir);
- assertCounts(1, 1, 0, PathUtils.visitFileTree(visitor, tempDir));
+ PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0"), tempDirPath);
+ assertCounts(1, 1, 0, PathUtils.visitFileTree(visitor, tempDirPath));
// This will throw if not empty.
- Files.deleteIfExists(tempDir);
+ Files.deleteIfExists(tempDirPath);
}
/**
* Tests a directory with one file of size 1.
*/
@ParameterizedTest
- @MethodSource("deletingPathVisitors")
+ @MethodSource(ARGS + "deletingPathVisitors")
public void testDeleteFolders1FileSize1(final DeletingPathVisitor visitor) throws IOException {
- PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDir);
- assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, tempDir));
+ PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDirPath);
+ assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, tempDirPath));
// This will throw if not empty.
- Files.deleteIfExists(tempDir);
+ Files.deleteIfExists(tempDirPath);
}
/**
* Tests a directory with one file of size 1 but skip that file.
*/
@ParameterizedTest
- @MethodSource("pathCounters")
+ @MethodSource(ARGS + "pathCounters")
public void testDeleteFolders1FileSize1Skip(final PathCounters pathCounters) throws IOException {
- PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDir);
+ PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDirPath);
final String skipFileName = "file-size-1.bin";
final CountingPathVisitor visitor = new DeletingPathVisitor(pathCounters, skipFileName);
- assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, tempDir));
- final Path skippedFile = tempDir.resolve(skipFileName);
+ assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, tempDirPath));
+ final Path skippedFile = tempDirPath.resolve(skipFileName);
Assertions.assertTrue(Files.exists(skippedFile));
Files.delete(skippedFile);
}
@@ -108,11 +106,11 @@
* Tests a directory with two subdirectories, each containing one file of size 1.
*/
@ParameterizedTest
- @MethodSource("deletingPathVisitors")
+ @MethodSource(ARGS + "deletingPathVisitors")
public void testDeleteFolders2FileSize2(final DeletingPathVisitor visitor) throws IOException {
- PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2"), tempDir);
- assertCounts(3, 2, 2, PathUtils.visitFileTree(visitor, tempDir));
+ PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2"), tempDirPath);
+ assertCounts(3, 2, 2, PathUtils.visitFileTree(visitor, tempDirPath));
// This will throw if not empty.
- Files.deleteIfExists(tempDir);
+ Files.deleteIfExists(tempDirPath);
}
}
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
index 74c4540..a767a77 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -73,24 +73,6 @@
private static final String PATH_FIXTURE = "NOTICE.txt";
- /**
- * Creates directory test fixtures.
- * <ol>
- * <li>tempDirPath/subdir</li>
- * <li>tempDirPath/symlinked-dir -> tempDirPath/subdir</li>
- * </ol>
- *
- * @return Path to tempDirPath/subdir
- * @throws IOException if an I/O error occurs or the parent directory does not exist.
- */
- private Path createTempSymlinkedRelativeDir() throws IOException {
- final Path targetDir = tempDirPath.resolve("subdir");
- final Path symlinkDir = tempDirPath.resolve("symlinked-dir");
- Files.createDirectory(targetDir);
- Files.createSymbolicLink(symlinkDir, targetDir);
- return symlinkDir;
- }
-
private Path current() {
return PathUtils.current();
}
@@ -234,7 +216,7 @@
@Test
public void testCreateDirectoriesSymlink() throws IOException {
- final Path symlinkedDir = createTempSymlinkedRelativeDir();
+ final Path symlinkedDir = createTempSymlinkedRelativeDir(tempDirPath);
final String leafDirName = "child";
final Path newDirFollowed = PathUtils.createParentDirectories(symlinkedDir.resolve(leafDirName), PathUtils.NULL_LINK_OPTION);
assertEquals(Files.readSymbolicLink(symlinkedDir), newDirFollowed);
@@ -242,7 +224,7 @@
@Test
public void testCreateDirectoriesSymlinkClashing() throws IOException {
- final Path symlinkedDir = createTempSymlinkedRelativeDir();
+ final Path symlinkedDir = createTempSymlinkedRelativeDir(tempDirPath);
assertEquals(symlinkedDir, PathUtils.createParentDirectories(symlinkedDir.resolve("child")));
}
@@ -428,7 +410,7 @@
@Test
public void testNewOutputStreamNewFileInsideExistingSymlinkedDir() throws IOException {
- final Path symlinkDir = createTempSymlinkedRelativeDir();
+ final Path symlinkDir = createTempSymlinkedRelativeDir(tempDirPath);
final Path file = symlinkDir.resolve("test.txt");
try (OutputStream outputStream = PathUtils.newOutputStream(file, new LinkOption[] {})) {
// empty