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 <garydgreg...@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