Skip to content

Commit 00bf113

Browse files
author
Gary Gregory
committed
Add missing CleaningPathVisitor tests
1 parent 252f298 commit 00bf113

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
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.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
23+
import static org.junit.jupiter.api.Assertions.assertSame;
2124

2225
import java.io.IOException;
2326
import java.nio.file.Files;
@@ -68,7 +71,14 @@ public void testCleanEmptyDirectoryNullCtorArg(final PathCounters pathCounters)
6871
@MethodSource("cleaningPathVisitors")
6972
public void testCleanFolders1FileSize0(final CleaningPathVisitor visitor) throws IOException {
7073
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0"), tempDir);
71-
assertCounts(1, 1, 0, PathUtils.visitFileTree(visitor, tempDir));
74+
final CleaningPathVisitor visitFileTree = PathUtils.visitFileTree(visitor, tempDir);
75+
assertCounts(1, 1, 0, visitFileTree);
76+
assertSame(visitor, visitFileTree);
77+
//
78+
assertNotEquals(visitFileTree, CleaningPathVisitor.withLongCounters());
79+
assertNotEquals(visitFileTree.hashCode(), CleaningPathVisitor.withLongCounters().hashCode());
80+
assertEquals(visitFileTree, visitFileTree);
81+
assertEquals(visitFileTree.hashCode(), visitFileTree.hashCode());
7282
}
7383

7484
/**
@@ -78,7 +88,14 @@ public void testCleanFolders1FileSize0(final CleaningPathVisitor visitor) throws
7888
@MethodSource("cleaningPathVisitors")
7989
public void testCleanFolders1FileSize1(final CleaningPathVisitor visitor) throws IOException {
8090
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDir);
81-
assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, tempDir));
91+
final CleaningPathVisitor visitFileTree = PathUtils.visitFileTree(visitor, tempDir);
92+
assertCounts(1, 1, 1, visitFileTree);
93+
assertSame(visitor, visitFileTree);
94+
//
95+
assertNotEquals(visitFileTree, CleaningPathVisitor.withLongCounters());
96+
assertNotEquals(visitFileTree.hashCode(), CleaningPathVisitor.withLongCounters().hashCode());
97+
assertEquals(visitFileTree, visitFileTree);
98+
assertEquals(visitFileTree.hashCode(), visitFileTree.hashCode());
8299
}
83100

84101
/**
@@ -90,10 +107,17 @@ public void testCleanFolders1FileSize1Skip(final PathCounters pathCounters) thro
90107
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDir);
91108
final String skipFileName = "file-size-1.bin";
92109
final CountingPathVisitor visitor = new CleaningPathVisitor(pathCounters, skipFileName);
93-
assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, tempDir));
110+
final CountingPathVisitor visitFileTree = PathUtils.visitFileTree(visitor, tempDir);
111+
assertCounts(1, 1, 1, visitFileTree);
112+
assertSame(visitor, visitFileTree);
94113
final Path skippedFile = tempDir.resolve(skipFileName);
95114
Assertions.assertTrue(Files.exists(skippedFile));
96115
Files.delete(skippedFile);
116+
//
117+
assertNotEquals(visitFileTree, CleaningPathVisitor.withLongCounters());
118+
assertNotEquals(visitFileTree.hashCode(), CleaningPathVisitor.withLongCounters().hashCode());
119+
assertEquals(visitFileTree, visitFileTree);
120+
assertEquals(visitFileTree.hashCode(), visitFileTree.hashCode());
97121
}
98122

99123
/**
@@ -103,6 +127,13 @@ public void testCleanFolders1FileSize1Skip(final PathCounters pathCounters) thro
103127
@MethodSource("cleaningPathVisitors")
104128
public void testCleanFolders2FileSize2(final CleaningPathVisitor visitor) throws IOException {
105129
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2"), tempDir);
106-
assertCounts(3, 2, 2, PathUtils.visitFileTree(visitor, tempDir));
130+
final CleaningPathVisitor visitFileTree = PathUtils.visitFileTree(visitor, tempDir);
131+
assertCounts(3, 2, 2, visitFileTree);
132+
assertSame(visitor, visitFileTree);
133+
//
134+
assertNotEquals(visitFileTree, CleaningPathVisitor.withLongCounters());
135+
assertNotEquals(visitFileTree.hashCode(), CleaningPathVisitor.withLongCounters().hashCode());
136+
assertEquals(visitFileTree, visitFileTree);
137+
assertEquals(visitFileTree.hashCode(), visitFileTree.hashCode());
107138
}
108139
}

0 commit comments

Comments
 (0)