Skip to content

Commit 54e8c97

Browse files
author
Andrey Shcheglov
committed
IO-719: Fixed Windows-related test errors
1 parent b47e52a commit 54e8c97

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

src/test/java/org/apache/commons/io/file/PathUtilsTest.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePath() throws IO
115115
final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName()).toAbsolutePath();
116116
try {
117117
final Path archivePath = Paths.get("src/test/resources/org/apache/commons/io/test.jar");
118-
try (final FileSystem archive = FileSystems.newFileSystem(archivePath, (ClassLoader) null)) {
118+
try (final FileSystem archive = openArchive(archivePath, false)) {
119119
// relative jar -> absolute dir
120120
Path sourceDir = archive.getPath("dir1");
121121
PathUtils.copyDirectory(sourceDir, tempDir);
@@ -135,11 +135,7 @@ public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePath() throws IO
135135
public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePathReverse() throws IOException {
136136
final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
137137
try {
138-
final Path archivePath = tempDir.resolve("test.jar");
139-
final URI uri = URI.create("jar:file:" + archivePath.toAbsolutePath().toString());
140-
final Map<String, String> env = new HashMap<>();
141-
env.put("create", "true");
142-
try (final FileSystem archive = FileSystems.newFileSystem(uri, env, null)) {
138+
try (final FileSystem archive = openArchive(tempDir.resolve("test.jar"), true)) {
143139
// absolute dir -> relative jar
144140
Path targetDir = archive.getPath("target");
145141
Files.createDirectory(targetDir);
@@ -160,21 +156,22 @@ public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePathReverse() th
160156

161157
@Test
162158
public void testCopyDirectoryForDifferentFilesystemsWithRelativePath() throws IOException {
163-
Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
164-
final Path cwd = Paths.get("").toAbsolutePath();
165-
tempDir = cwd.relativize(tempDir);
159+
final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
166160
try {
167161
final Path archivePath = Paths.get("src/test/resources/org/apache/commons/io/test.jar");
168-
try (final FileSystem archive = FileSystems.newFileSystem(archivePath, (ClassLoader) null)) {
162+
try (final FileSystem archive = openArchive(archivePath, false);
163+
final FileSystem targetArchive = openArchive(tempDir.resolve("test.jar"), true)) {
164+
Path targetDir = targetArchive.getPath("targetDir");
165+
Files.createDirectory(targetDir);
169166
// relative jar -> relative dir
170167
Path sourceDir = archive.getPath("next");
171-
PathUtils.copyDirectory(sourceDir, tempDir);
172-
assertTrue(Files.exists(tempDir.resolve("dir")));
168+
PathUtils.copyDirectory(sourceDir, targetDir);
169+
assertTrue(Files.exists(targetDir.resolve("dir")));
173170

174171
// absolute jar -> relative dir
175172
sourceDir = archive.getPath("/dir1");
176-
PathUtils.copyDirectory(sourceDir, tempDir);
177-
assertTrue(Files.exists(tempDir.resolve("f1")));
173+
PathUtils.copyDirectory(sourceDir, targetDir);
174+
assertTrue(Files.exists(targetDir.resolve("f1")));
178175
}
179176
} finally {
180177
PathUtils.deleteDirectory(tempDir);
@@ -185,11 +182,7 @@ public void testCopyDirectoryForDifferentFilesystemsWithRelativePath() throws IO
185182
public void testCopyDirectoryForDifferentFilesystemsWithRelativePathReverse() throws IOException {
186183
final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
187184
try {
188-
final Path archivePath = tempDir.resolve("test.jar");
189-
final URI uri = URI.create("jar:file:" + archivePath.toAbsolutePath().toString());
190-
final Map<String, String> env = new HashMap<>();
191-
env.put("create", "true");
192-
try (final FileSystem archive = FileSystems.newFileSystem(uri, env, null)) {
185+
try (final FileSystem archive = openArchive(tempDir.resolve("test.jar"), true)) {
193186
// relative dir -> relative jar
194187
Path targetDir = archive.getPath("target");
195188
Files.createDirectory(targetDir);
@@ -206,5 +199,19 @@ public void testCopyDirectoryForDifferentFilesystemsWithRelativePathReverse() th
206199
PathUtils.deleteDirectory(tempDir);
207200
}
208201
}
202+
203+
private FileSystem openArchive(Path p, boolean createNew) throws IOException {
204+
final FileSystem archive;
205+
if (createNew) {
206+
Map<String, String> env = new HashMap<>();
207+
env.put("create", "true");
208+
URI fileUri = p.toAbsolutePath().toUri();
209+
final URI uri = URI.create("jar:" + fileUri.toASCIIString());
210+
archive = FileSystems.newFileSystem(uri, env, null);
211+
} else {
212+
archive = FileSystems.newFileSystem(p, (ClassLoader) null);
213+
}
214+
return archive;
215+
}
209216

210217
}

0 commit comments

Comments
 (0)