PathUtilsTest does not need two temp dirs.
MODIFY
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -69,8 +69,6 @@ private FileSystem openArchive(final Path p, final boolean createNew) throws IOE
@Test
public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePath() throws IOException {
- final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName()).toAbsolutePath();
- try {
final Path archivePath = Paths.get(TEST_JAR_PATH);
try (final FileSystem archive = openArchive(archivePath, false)) {
// relative jar -> absolute dir
@@ -83,21 +81,15 @@ public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePath() throws IO
PathUtils.copyDirectory(sourceDir, tempDir);
assertTrue(Files.exists(tempDir.resolve("dir")));
}
- } finally {
- PathUtils.deleteDirectory(tempDir);
- }
}
@Test
public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePathReverse() throws IOException {
- final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
- try {
try (final FileSystem archive = openArchive(tempDir.resolve(TEST_JAR_NAME), true)) {
// absolute dir -> relative jar
Path targetDir = archive.getPath("target");
Files.createDirectory(targetDir);
- final Path sourceDir = Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2")
- .toAbsolutePath();
+ final Path sourceDir = Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2").toAbsolutePath();
PathUtils.copyDirectory(sourceDir, targetDir);
assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
@@ -106,18 +98,12 @@ public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePathReverse() th
PathUtils.copyDirectory(sourceDir, targetDir);
assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
}
- } finally {
- PathUtils.deleteDirectory(tempDir);
- }
}
@Test
public void testCopyDirectoryForDifferentFilesystemsWithRelativePath() throws IOException {
- final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
- try {
final Path archivePath = Paths.get(TEST_JAR_PATH);
- try (final FileSystem archive = openArchive(archivePath, false);
- final FileSystem targetArchive = openArchive(tempDir.resolve(TEST_JAR_NAME), true)) {
+ try (final FileSystem archive = openArchive(archivePath, false); final FileSystem targetArchive = openArchive(tempDir.resolve(TEST_JAR_NAME), true)) {
final Path targetDir = targetArchive.getPath("targetDir");
Files.createDirectory(targetDir);
// relative jar -> relative dir
@@ -130,15 +116,10 @@ public void testCopyDirectoryForDifferentFilesystemsWithRelativePath() throws IO
PathUtils.copyDirectory(sourceDir, targetDir);
assertTrue(Files.exists(targetDir.resolve("f1")));
}
- } finally {
- PathUtils.deleteDirectory(tempDir);
- }
}
@Test
public void testCopyDirectoryForDifferentFilesystemsWithRelativePathReverse() throws IOException {
- final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
- try {
try (final FileSystem archive = openArchive(tempDir.resolve(TEST_JAR_NAME), true)) {
// relative dir -> relative jar
Path targetDir = archive.getPath("target");
@@ -152,23 +133,14 @@ public void testCopyDirectoryForDifferentFilesystemsWithRelativePathReverse() th
PathUtils.copyDirectory(sourceDir, targetDir);
assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
}
- } finally {
- PathUtils.deleteDirectory(tempDir);
- }
}
@Test
public void testCopyFile() throws IOException {
- final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
- try {
- final Path sourceFile = Paths
- .get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/file-size-1.bin");
+ final Path sourceFile = Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/file-size-1.bin");
final Path targetFile = PathUtils.copyFileToDirectory(sourceFile, tempDir);
assertTrue(Files.exists(targetFile));
assertEquals(Files.size(sourceFile), Files.size(targetFile));
- } finally {
- PathUtils.deleteDirectory(tempDir);
- }
}
@Test

PathUtilsTest does not need two temp dirs.