You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/01/01 16:41:21 UTC

(commons-io) branch master updated (33551deb -> 653fd910)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


    from 33551deb ClosedInputStream.read(byte[], int, int) does not always return -1
     new fccd8617 Add missingg tests
     new 653fd910 Javadoc

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/commons/io/FileUtilsTest.java  | 100 +++++++++++----------
 .../apache/commons/io/input/ClosedReaderTest.java  |  62 ++++++++++++-
 2 files changed, 110 insertions(+), 52 deletions(-)


(commons-io) 01/02: Add missingg tests

Posted by gg...@apache.org.
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 fccd86175bb9cf34bcb34fdd83b982a6cd6e961b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 1 11:39:47 2024 -0500

    Add missingg tests
---
 .../apache/commons/io/input/ClosedReaderTest.java  | 62 ++++++++++++++++++++--
 1 file changed, 59 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/input/ClosedReaderTest.java b/src/test/java/org/apache/commons/io/input/ClosedReaderTest.java
index 9fd5dccf..3b0b8830 100644
--- a/src/test/java/org/apache/commons/io/input/ClosedReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/ClosedReaderTest.java
@@ -16,8 +16,13 @@
  */
 package org.apache.commons.io.input;
 
+import static org.apache.commons.io.IOUtils.EOF;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.CharBuffer;
+
 import org.junit.jupiter.api.Test;
 
 /**
@@ -25,10 +30,61 @@ import org.junit.jupiter.api.Test;
  */
 public class ClosedReaderTest {
 
+    private void assertEof(final Reader reader) throws IOException {
+        assertEquals(EOF, reader.read(), "read()");
+    }
+
+    @Test
+    public void testRead() throws IOException {
+        try (Reader reader = new ClosedReader()) {
+            assertEof(reader);
+        }
+    }
+
+    @Test
+    public void testReadArray() throws Exception {
+        try (Reader reader = new ClosedReader()) {
+            assertEquals(EOF, reader.read(new char[4096]));
+            assertEquals(EOF, reader.read(new char[1]));
+            assertEquals(EOF, reader.read(new char[0]));
+        }
+    }
+
+    @Test
+    public void testReadArrayIndex() throws Exception {
+        try (Reader reader = new ClosedReader()) {
+            assertEquals(EOF, reader.read(CharBuffer.wrap(new char[4096])));
+            assertEquals(EOF, reader.read(CharBuffer.wrap(new char[1])));
+            assertEquals(EOF, reader.read(CharBuffer.wrap(new char[0])));
+        }
+    }
+
+    @Test
+    public void testReadCharBuffer() throws Exception {
+        try (Reader reader = new ClosedReader()) {
+            assertEquals(EOF, reader.read(new char[4096]));
+            assertEquals(EOF, reader.read(new char[1]));
+            assertEquals(EOF, reader.read(new char[0]));
+        }
+    }
+
+    @Test
+    public void testSingleton() throws Exception {
+        try (@SuppressWarnings("deprecation")
+        Reader reader = ClosedReader.CLOSED_READER) {
+            assertEof(reader);
+        }
+        try (Reader reader = ClosedReader.INSTANCE) {
+            assertEof(reader);
+        }
+    }
+
     @Test
-    public void testRead() throws Exception {
-        try (ClosedReader cr = new ClosedReader()) {
-            assertEquals(-1, cr.read(new char[10], 0, 10), "read(cbuf, off, len)");
+    public void testSkip() throws Exception {
+        try (Reader reader = new ClosedReader()) {
+            assertEquals(0, reader.skip(4096));
+            assertEquals(0, reader.skip(1));
+            assertEquals(0, reader.skip(0));
         }
     }
 


(commons-io) 02/02: Javadoc

Posted by gg...@apache.org.
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 653fd9100718b20ba6ccd8981a5adb2bb714c5ee
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 1 11:41:16 2024 -0500

    Javadoc
    
    Keep members sorted
---
 .../java/org/apache/commons/io/FileUtilsTest.java  | 100 +++++++++++----------
 1 file changed, 51 insertions(+), 49 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 84eae472..e7b3202e 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -757,6 +757,40 @@ public class FileUtilsTest extends AbstractTempDirTest {
         assertTrue(FileUtils.contentEqualsIgnoreEOL(file1, file2, null));
     }
 
+    /**
+     * Tests IO-807.
+     */
+    @Test
+    public void testCopyDirectory_brokenSymLink() throws IOException {
+        // Make a file
+        final File sourceDirectory = new File(tempDirFile, "source_directory");
+        sourceDirectory.mkdir();
+        final File targetFile = new File(sourceDirectory, "hello.txt");
+        FileUtils.writeStringToFile(targetFile, "HELLO WORLD", "UTF8");
+
+        // Make a symlink to the file
+        final Path targetPath = targetFile.toPath();
+        final Path linkPath = sourceDirectory.toPath().resolve("linkfile");
+        Files.createSymbolicLink(linkPath, targetPath);
+        assumeTrue(Files.isSymbolicLink(linkPath), () -> "Expected a symlink here: " + linkPath);
+        assumeTrue(Files.exists(linkPath));
+        assumeTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS));
+
+        // Delete the file file to break the symlink
+        assumeTrue(targetFile.delete());
+        assumeFalse(Files.exists(linkPath));
+        assumeTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS));
+
+        // Now copy sourceDirectory, including the broken link, to another directory
+        final File destination = new File(tempDirFile, "destination");
+        final FileNotFoundException thrown = assertThrows(
+                FileNotFoundException.class,
+                () -> FileUtils.copyDirectory(sourceDirectory, destination),
+                "ignored broken link"
+        );
+        assertTrue(thrown.getMessage().contains("linkfile' does not exist"));
+    }
+
     @Test
     public void testCopyDirectoryExceptions() {
         //
@@ -794,55 +828,6 @@ public class FileUtilsTest extends AbstractTempDirTest {
         assertEquals("file3.txt", files.get(2).getName());
     }
 
-    @Test
-    public void testToURLs2() {
-        final File[] files = new File[] {
-            new File(tempDirFile, "file1.txt"),
-            null,
-        };
-        assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
-                "Can't convert null URL");
-    }
-
-    @Test
-    public void testToURLs3() {
-        final File[] files = null;
-        assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
-                "Can't convert null list");
-    }
-
-    // IO-807
-    @Test
-    public void testCopyDirectory_brokenSymLink() throws IOException {
-        // Make a file
-        final File sourceDirectory = new File(tempDirFile, "source_directory");
-        sourceDirectory.mkdir();
-        final File targetFile = new File(sourceDirectory, "hello.txt");
-        FileUtils.writeStringToFile(targetFile, "HELLO WORLD", "UTF8");
-
-        // Make a symlink to the file
-        final Path targetPath = targetFile.toPath();
-        final Path linkPath = sourceDirectory.toPath().resolve("linkfile");
-        Files.createSymbolicLink(linkPath, targetPath);
-        assumeTrue(Files.isSymbolicLink(linkPath), () -> "Expected a symlink here: " + linkPath);
-        assumeTrue(Files.exists(linkPath));
-        assumeTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS));
-
-        // Delete the file file to break the symlink
-        assumeTrue(targetFile.delete());
-        assumeFalse(Files.exists(linkPath));
-        assumeTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS));
-
-        // Now copy sourceDirectory, including the broken link, to another directory
-        final File destination = new File(tempDirFile, "destination");
-        final FileNotFoundException thrown = assertThrows(
-                FileNotFoundException.class,
-                () -> FileUtils.copyDirectory(sourceDirectory, destination),
-                "ignored broken link"
-        );
-        assertTrue(thrown.getMessage().contains("linkfile' does not exist"));
-    }
-
     @Test
     public void testCopyDirectoryPreserveDates() throws Exception {
         final File source = new File(tempDirFile, "source");
@@ -2831,6 +2816,23 @@ public class FileUtilsTest extends AbstractTempDirTest {
         assertTrue(urls[2].toExternalForm().contains("test%20file.txt"));
     }
 
+    @Test
+    public void testToURLs2() {
+        final File[] files = new File[] {
+            new File(tempDirFile, "file1.txt"),
+            null,
+        };
+        assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
+                "Can't convert null URL");
+    }
+
+    @Test
+    public void testToURLs3() {
+        final File[] files = null;
+        assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
+                "Can't convert null list");
+    }
+
     @Test
     public void testToURLs3a() throws Exception {
         final File[] files = {}; // empty array