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 2021/08/04 20:45:11 UTC
[commons-io] branch master updated: PathUtilsTest does not need two
temp dirs.
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 1c668e0 PathUtilsTest does not need two temp dirs.
1c668e0 is described below
commit 1c668e0658d03e52c7b8e9255be33385d8789ac6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 4 16:45:09 2021 -0400
PathUtilsTest does not need two temp dirs.
---
.../org/apache/commons/io/file/PathUtilsTest.java | 132 ++++++++-------------
1 file changed, 52 insertions(+), 80 deletions(-)
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 b5561a9..ef3e5b8 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -69,106 +69,78 @@ public class PathUtilsTest extends TestArguments {
@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
- Path sourceDir = archive.getPath("dir1");
- PathUtils.copyDirectory(sourceDir, tempDir);
- assertTrue(Files.exists(tempDir.resolve("f1")));
-
- // absolute jar -> absolute dir
- sourceDir = archive.getPath("/next");
- PathUtils.copyDirectory(sourceDir, tempDir);
- assertTrue(Files.exists(tempDir.resolve("dir")));
- }
- } finally {
- PathUtils.deleteDirectory(tempDir);
+ final Path archivePath = Paths.get(TEST_JAR_PATH);
+ try (final FileSystem archive = openArchive(archivePath, false)) {
+ // relative jar -> absolute dir
+ Path sourceDir = archive.getPath("dir1");
+ PathUtils.copyDirectory(sourceDir, tempDir);
+ assertTrue(Files.exists(tempDir.resolve("f1")));
+
+ // absolute jar -> absolute dir
+ sourceDir = archive.getPath("/next");
+ PathUtils.copyDirectory(sourceDir, tempDir);
+ assertTrue(Files.exists(tempDir.resolve("dir")));
}
}
@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();
- PathUtils.copyDirectory(sourceDir, targetDir);
- assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
-
- // absolute dir -> absolute jar
- targetDir = archive.getPath("/");
- PathUtils.copyDirectory(sourceDir, targetDir);
- assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
- }
- } finally {
- PathUtils.deleteDirectory(tempDir);
+ 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();
+ PathUtils.copyDirectory(sourceDir, targetDir);
+ assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
+
+ // absolute dir -> absolute jar
+ targetDir = archive.getPath("/");
+ PathUtils.copyDirectory(sourceDir, targetDir);
+ assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
}
}
@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)) {
- final Path targetDir = targetArchive.getPath("targetDir");
- Files.createDirectory(targetDir);
- // relative jar -> relative dir
- Path sourceDir = archive.getPath("next");
- PathUtils.copyDirectory(sourceDir, targetDir);
- assertTrue(Files.exists(targetDir.resolve("dir")));
-
- // absolute jar -> relative dir
- sourceDir = archive.getPath("/dir1");
- PathUtils.copyDirectory(sourceDir, targetDir);
- assertTrue(Files.exists(targetDir.resolve("f1")));
- }
- } finally {
- PathUtils.deleteDirectory(tempDir);
+ 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)) {
+ final Path targetDir = targetArchive.getPath("targetDir");
+ Files.createDirectory(targetDir);
+ // relative jar -> relative dir
+ Path sourceDir = archive.getPath("next");
+ PathUtils.copyDirectory(sourceDir, targetDir);
+ assertTrue(Files.exists(targetDir.resolve("dir")));
+
+ // absolute jar -> relative dir
+ sourceDir = archive.getPath("/dir1");
+ PathUtils.copyDirectory(sourceDir, targetDir);
+ assertTrue(Files.exists(targetDir.resolve("f1")));
}
}
@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");
- Files.createDirectory(targetDir);
- final Path sourceDir = Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2");
- PathUtils.copyDirectory(sourceDir, targetDir);
- assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
-
- // relative dir -> absolute jar
- targetDir = archive.getPath("/");
- PathUtils.copyDirectory(sourceDir, targetDir);
- assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
- }
- } finally {
- PathUtils.deleteDirectory(tempDir);
+ try (final FileSystem archive = openArchive(tempDir.resolve(TEST_JAR_NAME), true)) {
+ // relative 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");
+ PathUtils.copyDirectory(sourceDir, targetDir);
+ assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
+
+ // relative dir -> absolute jar
+ targetDir = archive.getPath("/");
+ PathUtils.copyDirectory(sourceDir, targetDir);
+ assertTrue(Files.exists(targetDir.resolve("dirs-a-file-size-1")));
}
}
@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 targetFile = PathUtils.copyFileToDirectory(sourceFile, tempDir);
- assertTrue(Files.exists(targetFile));
- assertEquals(Files.size(sourceFile), Files.size(targetFile));
- } finally {
- PathUtils.deleteDirectory(tempDir);
- }
+ 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));
}
@Test