This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 1215693fbd6bbc13e2a09a22007a536cab5467f7 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Apr 4 07:36:16 2024 -0400 Add missing test --- .../commons/io/file/DeletingPathVisitorTest.java | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java b/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java index a0e3b3f9f..1660922b0 100644 --- a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java +++ b/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java @@ -18,7 +18,9 @@ package org.apache.commons.io.file; import static org.apache.commons.io.file.CounterAssertions.assertCounts; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; @@ -118,41 +120,60 @@ public class DeletingPathVisitorTest extends AbstractTempDirTest { Files.deleteIfExists(tempDirPath); } + @Test + public void testEqualsHashCode() { + final DeletingPathVisitor visitor0 = DeletingPathVisitor.withLongCounters(); + final DeletingPathVisitor visitor1 = DeletingPathVisitor.withLongCounters(); + assertEquals(visitor0, visitor0); + assertEquals(visitor0, visitor1); + assertEquals(visitor1, visitor0); + assertEquals(visitor0.hashCode(), visitor0.hashCode()); + assertEquals(visitor0.hashCode(), visitor1.hashCode()); + assertEquals(visitor1.hashCode(), visitor0.hashCode()); + visitor0.getPathCounters().getByteCounter().increment(); + assertEquals(visitor0, visitor0); + assertNotEquals(visitor0, visitor1); + assertNotEquals(visitor1, visitor0); + assertEquals(visitor0.hashCode(), visitor0.hashCode()); + assertNotEquals(visitor0.hashCode(), visitor1.hashCode()); + assertNotEquals(visitor1.hashCode(), visitor0.hashCode()); + } + /** * Tests https://issues.apache.org/jira/browse/IO-850 */ @Test - public void testIO850DirectoriesOnly() throws IOException { + public void testIO850DirectoriesAndFiles() throws IOException { final Path rootDir = Files.createDirectory(managedTempDirPath.resolve("IO850")); createTempSymlinkedRelativeDir(rootDir); final Path targetDir = rootDir.resolve(SUB_DIR); final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR); + Files.write(targetDir.resolve("file0.txt"), "Hello".getBytes(StandardCharsets.UTF_8)); + final Path subDir0 = Files.createDirectory(targetDir.resolve("subDir0")); + Files.write(subDir0.resolve("file1.txt"), "Hello".getBytes(StandardCharsets.UTF_8)); final DeletingPathVisitor visitor = DeletingPathVisitor.withLongCounters(); Files.walkFileTree(rootDir, visitor); assertFalse(Files.exists(targetDir)); assertFalse(Files.exists(symlinkDir)); assertFalse(Files.exists(rootDir)); assertTrue(visitor.getPathCounters().getDirectoryCounter().get() > 0); + assertTrue(visitor.getPathCounters().getFileCounter().get() > 0); } /** * Tests https://issues.apache.org/jira/browse/IO-850 */ @Test - public void testIO850DirectoriesAndFiles() throws IOException { + public void testIO850DirectoriesOnly() throws IOException { final Path rootDir = Files.createDirectory(managedTempDirPath.resolve("IO850")); createTempSymlinkedRelativeDir(rootDir); final Path targetDir = rootDir.resolve(SUB_DIR); final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR); - Files.write(targetDir.resolve("file0.txt"), "Hello".getBytes(StandardCharsets.UTF_8)); - final Path subDir0 = Files.createDirectory(targetDir.resolve("subDir0")); - Files.write(subDir0.resolve("file1.txt"), "Hello".getBytes(StandardCharsets.UTF_8)); final DeletingPathVisitor visitor = DeletingPathVisitor.withLongCounters(); Files.walkFileTree(rootDir, visitor); assertFalse(Files.exists(targetDir)); assertFalse(Files.exists(symlinkDir)); assertFalse(Files.exists(rootDir)); assertTrue(visitor.getPathCounters().getDirectoryCounter().get() > 0); - assertTrue(visitor.getPathCounters().getFileCounter().get() > 0); } }