Skip to content

Commit d3910a9

Browse files
committed
Test PathUtils.deleteDirectory(Path)
1 parent 916cda6 commit d3910a9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
package org.apache.commons.io.file;
1919

2020
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.assertThrows;
2123

2224
import java.io.IOException;
2325
import java.nio.file.Files;
26+
import java.nio.file.Path;
2427
import java.nio.file.Paths;
2528

2629
import org.junit.jupiter.api.Test;
@@ -30,6 +33,18 @@
3033
*/
3134
public class PathUtilsDeleteDirectoryTest extends AbstractTempDirTest {
3235

36+
@Test
37+
public void testDeleteAbsentDirectory() throws IOException {
38+
final Path absent = tempDirPath.resolve("ThisDirectoryDoesNotExist");
39+
assertFalse(Files.exists(absent));
40+
final Class<IllegalArgumentException> expectedType = IllegalArgumentException.class;
41+
assertThrows(expectedType, () -> PathUtils.deleteDirectory(absent));
42+
assertThrows(expectedType, () -> PathUtils.deleteDirectory(absent, StandardDeleteOption.OVERRIDE_READ_ONLY));
43+
assertThrows(expectedType, () -> PathUtils.deleteDirectory(absent, PathUtils.EMPTY_DELETE_OPTION_ARRAY));
44+
// This will throw if not empty.
45+
Files.deleteIfExists(tempDirPath);
46+
}
47+
3348
/**
3449
* Tests a directory with one file of size 0.
3550
*/

0 commit comments

Comments
 (0)