1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.io.file;
19
20 import static org.apache.commons.io.file.CounterAssertions.assertCounts;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.io.TempDir;
30
31
32
33
34 class PathUtilsCleanDirectoryTest {
35
36 @TempDir
37 private Path tempDir;
38
39
40
41
42 @Test
43 void testCleanDirectory1FileSize0() throws IOException {
44 PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0"), tempDir);
45 assertCounts(1, 1, 0, PathUtils.cleanDirectory(tempDir));
46 assertTrue(Files.exists(tempDir));
47 }
48
49
50
51
52 @Test
53 void testCleanDirectory1FileSize1() throws IOException {
54 PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDir);
55 assertCounts(1, 1, 1, PathUtils.cleanDirectory(tempDir));
56 assertTrue(Files.exists(tempDir));
57 }
58
59
60
61
62 @Test
63 void testCleanDirectory2FileSize2() throws IOException {
64 PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2"), tempDir);
65 assertCounts(3, 2, 2, PathUtils.cleanDirectory(tempDir));
66 assertTrue(Files.exists(tempDir));
67 }
68
69
70
71
72 @Test
73 void testCleanEmptyDirectory() throws IOException {
74 assertCounts(1, 0, 0, PathUtils.cleanDirectory(tempDir));
75 assertTrue(Files.exists(tempDir));
76 }
77 }