|
18 | 18 | package org.apache.commons.io.file; |
19 | 19 |
|
20 | 20 | import static org.apache.commons.io.file.CounterAssertions.assertCounts; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
21 | 23 |
|
22 | 24 | import java.io.IOException; |
| 25 | +import java.nio.charset.StandardCharsets; |
23 | 26 | import java.nio.file.Files; |
24 | 27 | import java.nio.file.Path; |
25 | 28 | import java.nio.file.Paths; |
26 | 29 |
|
27 | 30 | import org.apache.commons.io.file.Counters.PathCounters; |
28 | 31 | import org.junit.jupiter.api.Assertions; |
| 32 | +import org.junit.jupiter.api.Test; |
29 | 33 | import org.junit.jupiter.params.ParameterizedTest; |
30 | 34 | import org.junit.jupiter.params.provider.MethodSource; |
31 | 35 |
|
@@ -113,4 +117,42 @@ public void testDeleteFolders2FileSize2(final DeletingPathVisitor visitor) throw |
113 | 117 | // This will throw if not empty. |
114 | 118 | Files.deleteIfExists(tempDirPath); |
115 | 119 | } |
| 120 | + |
| 121 | + /** |
| 122 | + * Tests https://issues.apache.org/jira/browse/IO-850 |
| 123 | + */ |
| 124 | + @Test |
| 125 | + public void testIO850DirectoriesOnly() throws IOException { |
| 126 | + final Path rootDir = Files.createDirectory(managedTempDirPath.resolve("IO850")); |
| 127 | + createTempSymlinkedRelativeDir(rootDir); |
| 128 | + final Path targetDir = rootDir.resolve(SUB_DIR); |
| 129 | + final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR); |
| 130 | + final DeletingPathVisitor visitor = DeletingPathVisitor.withLongCounters(); |
| 131 | + Files.walkFileTree(rootDir, visitor); |
| 132 | + assertFalse(Files.exists(targetDir)); |
| 133 | + assertFalse(Files.exists(symlinkDir)); |
| 134 | + assertFalse(Files.exists(rootDir)); |
| 135 | + assertTrue(visitor.getPathCounters().getDirectoryCounter().get() > 0); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Tests https://issues.apache.org/jira/browse/IO-850 |
| 140 | + */ |
| 141 | + @Test |
| 142 | + public void testIO850DirectoriesAndFiles() throws IOException { |
| 143 | + final Path rootDir = Files.createDirectory(managedTempDirPath.resolve("IO850")); |
| 144 | + createTempSymlinkedRelativeDir(rootDir); |
| 145 | + final Path targetDir = rootDir.resolve(SUB_DIR); |
| 146 | + final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR); |
| 147 | + Files.write(targetDir.resolve("file0.txt"), "Hello".getBytes(StandardCharsets.UTF_8)); |
| 148 | + final Path subDir0 = Files.createDirectory(targetDir.resolve("subDir0")); |
| 149 | + Files.write(subDir0.resolve("file1.txt"), "Hello".getBytes(StandardCharsets.UTF_8)); |
| 150 | + final DeletingPathVisitor visitor = DeletingPathVisitor.withLongCounters(); |
| 151 | + Files.walkFileTree(rootDir, visitor); |
| 152 | + assertFalse(Files.exists(targetDir)); |
| 153 | + assertFalse(Files.exists(symlinkDir)); |
| 154 | + assertFalse(Files.exists(rootDir)); |
| 155 | + assertTrue(visitor.getPathCounters().getDirectoryCounter().get() > 0); |
| 156 | + assertTrue(visitor.getPathCounters().getFileCounter().get() > 0); |
| 157 | + } |
116 | 158 | } |
0 commit comments