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
22 import java.io.File;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.function.Supplier;
28 import java.util.stream.Stream;
29
30 import org.apache.commons.io.filefilter.AndFileFilter;
31 import org.apache.commons.io.filefilter.DirectoryFileFilter;
32 import org.apache.commons.io.filefilter.EmptyFileFilter;
33 import org.apache.commons.io.filefilter.PathVisitorFileFilter;
34 import org.junit.jupiter.api.io.TempDir;
35 import org.junit.jupiter.params.ParameterizedTest;
36 import org.junit.jupiter.params.provider.Arguments;
37 import org.junit.jupiter.params.provider.MethodSource;
38
39
40
41
42 public class PathUtilsVisitorTest {
43
44 static Stream<Arguments> testParameters() {
45 return AccumulatorPathVisitorTest.testParameters();
46 }
47
48 @TempDir
49 File tempDirFile;
50
51
52
53
54 @ParameterizedTest
55 @MethodSource("testParameters")
56 public void testCountEmptyFolder(final Supplier<AccumulatorPathVisitor> supplier) throws IOException {
57 final Path tempDir = tempDirFile.toPath();
58 final CountingPathVisitor countingPathVisitor = CountingPathVisitor.withLongCounters();
59 final PathVisitorFileFilter countingFileFilter = new PathVisitorFileFilter(countingPathVisitor);
60 Files.walkFileTree(tempDir,
61 new AndFileFilter(countingFileFilter, DirectoryFileFilter.INSTANCE, EmptyFileFilter.EMPTY));
62 assertCounts(1, 0, 0, countingPathVisitor.getPathCounters());
63 }
64
65
66
67
68 @ParameterizedTest
69 @MethodSource("testParameters")
70 public void testCountFolders1FileSize0(final Supplier<AccumulatorPathVisitor> supplier) throws IOException {
71 final CountingPathVisitor countingPathVisitor = CountingPathVisitor.withLongCounters();
72 final PathVisitorFileFilter countingFileFilter = new PathVisitorFileFilter(countingPathVisitor);
73 Files.walkFileTree(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0"),
74 countingFileFilter);
75 assertCounts(1, 1, 0, countingPathVisitor.getPathCounters());
76 }
77
78
79
80
81 @ParameterizedTest
82 @MethodSource("testParameters")
83 public void testCountFolders1FileSize1(final Supplier<AccumulatorPathVisitor> supplier) throws IOException {
84 final CountingPathVisitor countingPathVisitor = CountingPathVisitor.withLongCounters();
85 final PathVisitorFileFilter countingFileFilter = new PathVisitorFileFilter(countingPathVisitor);
86 Files.walkFileTree(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"),
87 countingFileFilter);
88 assertCounts(1, 1, 1, countingPathVisitor.getPathCounters());
89 }
90
91
92
93
94 @ParameterizedTest
95 @MethodSource("testParameters")
96 public void testCountFolders2FileSize2(final Supplier<AccumulatorPathVisitor> supplier) throws IOException {
97 final CountingPathVisitor countingPathVisitor = CountingPathVisitor.withLongCounters();
98 final PathVisitorFileFilter countingFileFilter = new PathVisitorFileFilter(countingPathVisitor);
99 Files.walkFileTree(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2"),
100 countingFileFilter);
101 assertCounts(3, 2, 2, countingPathVisitor.getPathCounters());
102 }
103 }