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 2025/05/06 15:01:51 UTC

(commons-io) 02/02: Reduce vertical whitespace

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 2094aed41832a7a39538b954a5f95e9ee1c149ab
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Tue May 6 11:01:37 2025 -0400

    Reduce vertical whitespace
---
 .../java/org/apache/commons/io/FileUtilsTest.java  | 102 +++------------------
 1 file changed, 15 insertions(+), 87 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 5c63c8915..210f13f2c 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -2825,30 +2825,23 @@ public void testReadLines_IOExceptionOnPosixFileSystem() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "cant-read.txt");
         TestUtils.createFile(file, 100);
         Files.setPosixFilePermissions(file.toPath(), PosixFilePermissions.fromString("---------"));
-
         assertThrows(IOException.class, () -> FileUtils.readLines(file));
     }
 
     @Test
     public void testSizeOf() throws Exception {
         final File file = new File(tempDirFile, getName());
-
         // Null argument
         assertThrows(NullPointerException.class, () -> FileUtils.sizeOf(null));
-
         // Non-existent file
         assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOf(file));
-
         // Creates file
         file.createNewFile();
-
         // New file
         assertEquals(0, FileUtils.sizeOf(file));
         file.delete();
-
         // Existing file
         assertEquals(testFile1Size, FileUtils.sizeOf(testFile1), "Unexpected files size");
-
         // Existing directory
         assertEquals(TEST_DIRECTORY_SIZE, FileUtils.sizeOf(tempDirFile), "Unexpected directory size");
     }
@@ -2856,26 +2849,19 @@ public void testSizeOf() throws Exception {
     @Test
     public void testSizeOfAsBigInteger() throws Exception {
         final File file = new File(tempDirFile, getName());
-
         // Null argument
         assertThrows(NullPointerException.class, () -> FileUtils.sizeOfAsBigInteger(null));
         // Non-existent file
         assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfAsBigInteger(file));
-
         // Creates file
         file.createNewFile();
-
         // New file
         assertEquals(BigInteger.ZERO, FileUtils.sizeOfAsBigInteger(file));
         file.delete();
-
         // Existing file
-        assertEquals(BigInteger.valueOf(testFile1Size), FileUtils.sizeOfAsBigInteger(testFile1),
-                "Unexpected files size");
-
+        assertEquals(BigInteger.valueOf(testFile1Size), FileUtils.sizeOfAsBigInteger(testFile1), "Unexpected files size");
         // Existing directory
-        assertEquals(TEST_DIRECTORY_SIZE_BI, FileUtils.sizeOfAsBigInteger(tempDirFile),
-                "Unexpected directory size");
+        assertEquals(TEST_DIRECTORY_SIZE_BI, FileUtils.sizeOfAsBigInteger(tempDirFile), "Unexpected directory size");
     }
 
     /**
@@ -2888,25 +2874,19 @@ public void testSizeOfAsBigInteger() throws Exception {
     @Test
     public void testSizeOfDirectory() throws Exception {
         final File file = new File(tempDirFile, getName());
-
         // Null argument
         assertThrows(NullPointerException.class, () -> FileUtils.sizeOfDirectory(null));
         // Non-existent file
         assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfAsBigInteger(file));
-
         // Creates file
         file.createNewFile();
-
         // Existing file
         assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfDirectory(file));
-
         // Existing directory
         file.delete();
         file.mkdir();
-
         // Create a cyclic symlink
         createCircularSymbolicLink(file);
-
         assertEquals(TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file), "Unexpected directory size");
     }
 
@@ -2920,30 +2900,22 @@ public void testSizeOfDirectory() throws Exception {
     @Test
     public void testSizeOfDirectoryAsBigInteger() throws Exception {
         final File file = new File(tempDirFile, getName());
-
         // Null argument
         assertThrows(NullPointerException.class, () -> FileUtils.sizeOfDirectoryAsBigInteger(null));
         // Non-existent file
         assertThrows(UncheckedIOException.class, () -> FileUtils.sizeOfDirectoryAsBigInteger(file));
-
         // Creates file
         file.createNewFile();
-
         // Existing file
         assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfDirectoryAsBigInteger(file));
-
         // Existing directory
         file.delete();
         file.mkdir();
-
         createCircularSymbolicLink(file);
-
         assertEquals(TEST_DIRECTORY_SIZE_BI, FileUtils.sizeOfDirectoryAsBigInteger(file), "Unexpected directory size");
-
         // Existing directory which size is greater than zero
         file.delete();
         file.mkdir();
-
         final File nonEmptyFile = new File(file, "non-emptyFile" + System.nanoTime());
         assertTrue(nonEmptyFile.getParentFile().exists(), () -> "Cannot create file " + nonEmptyFile + " as the parent directory does not exist");
         final OutputStream output = new BufferedOutputStream(Files.newOutputStream(nonEmptyFile.toPath()));
@@ -2952,9 +2924,7 @@ public void testSizeOfDirectoryAsBigInteger() throws Exception {
         } finally {
             IOUtils.closeQuietly(output);
         }
-
         assertEquals(TEST_DIRECTORY_SIZE_GT_ZERO_BI, FileUtils.sizeOfDirectoryAsBigInteger(file), "Unexpected directory size");
-
         nonEmptyFile.delete();
         file.delete();
     }
@@ -3055,7 +3025,6 @@ public void testToFileUtf8() throws Exception {
     @Test
     public void testTouch() throws IOException {
         assertThrows(NullPointerException.class, () -> FileUtils.touch(null));
-
         final File file = new File(tempDirFile, "touch.txt");
         if (file.exists()) {
             file.delete();
@@ -3069,7 +3038,7 @@ public void testTouch() throws IOException {
         }
         assertEquals(1, file.length(), "Wrote one byte to file");
         final long y2k = new GregorianCalendar(2000, 0, 1).getTime().getTime();
-        final boolean res = setLastModifiedMillis(file, y2k);  // 0L fails on Win98
+        final boolean res = setLastModifiedMillis(file, y2k); // 0L fails on Win98
         assertTrue(res, "Bad test: set lastModified failed");
         assertEquals(y2k, getLastModifiedMillis(file), "Bad test: set lastModified set incorrect value");
         final long nowMillis = System.currentTimeMillis();
@@ -3116,26 +3085,20 @@ public void testToURLs1() throws Exception {
 
     @Test
     public void testToURLs2() {
-        final File[] files = {
-            new File(tempDirFile, "file1.txt"),
-            null,
-        };
-        assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
-                "Can't convert null URL");
+        final File[] files = { 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");
+        assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files), "Can't convert null list");
     }
 
     @Test
     public void testToURLs3a() throws Exception {
         final File[] files = {}; // empty array
         final URL[] urls = FileUtils.toURLs(files);
-
         assertEquals(0, urls.length);
     }
 
@@ -3143,9 +3106,7 @@ public void testToURLs3a() throws Exception {
     public void testWrite_WithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.write(file, "this is brand new data", false);
-
         final String expected = "this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
@@ -3155,11 +3116,8 @@ public void testWrite_WithAppendOptionFalse_ShouldDeletePreviousFileLines() thro
     public void testWrite_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.write(file, "this is brand new data", true);
-
-        final String expected = "This line was there before you..."
-                + "this is brand new data";
+        final String expected = "This line was there before you...this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
     }
@@ -3176,9 +3134,7 @@ public void testWriteByteArrayToFile() throws Exception {
     public void testWriteByteArrayToFile_WithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.writeByteArrayToFile(file, "this is brand new data".getBytes(), false);
-
         final String expected = "this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
@@ -3188,11 +3144,8 @@ public void testWriteByteArrayToFile_WithAppendOptionFalse_ShouldDeletePreviousF
     public void testWriteByteArrayToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.writeByteArrayToFile(file, "this is brand new data".getBytes(), true);
-
-        final String expected = "This line was there before you..."
-                + "this is brand new data";
+        final String expected = "This line was there before you...this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
     }
@@ -3211,10 +3164,8 @@ public void testWriteByteArrayToFile_WithOffsetAndLength() throws Exception {
     public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_ShouldDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         final byte[] data = "SKIP_THIS_this is brand new data_AND_SKIP_THIS".getBytes(StandardCharsets.UTF_8);
         FileUtils.writeByteArrayToFile(file, data, 10, 22, false);
-
         final String expected = "this is brand new data";
         final String actual = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
         assertEquals(expected, actual);
@@ -3224,10 +3175,8 @@ public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_Sh
     public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         final byte[] data = "SKIP_THIS_this is brand new data_AND_SKIP_THIS".getBytes(StandardCharsets.UTF_8);
         FileUtils.writeByteArrayToFile(file, data, 10, 22, true);
-
         final String expected = "This line was there before you..." + "this is brand new data";
         final String actual = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
         assertEquals(expected, actual);
@@ -3251,16 +3200,12 @@ public void testWriteCharSequence2() throws Exception {
 
     @Test
     public void testWriteLines_3arg_nullSeparator() throws Exception {
-        final Object[] data = {
-                "hello", new StringBuffer("world"), "", "this is", null, "some text"};
+        final Object[] data = { "hello", new StringBuffer("world"), "", "this is", null, "some text" };
         final List<Object> list = Arrays.asList(data);
-
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeLines(file, StandardCharsets.US_ASCII.name(), list);
-
-        final String expected = "hello" + System.lineSeparator() + "world" + System.lineSeparator() +
-                System.lineSeparator() + "this is" + System.lineSeparator() +
-                System.lineSeparator() + "some text" + System.lineSeparator();
+        final String expected = "hello" + System.lineSeparator() + "world" + System.lineSeparator() + System.lineSeparator() + "this is"
+                + System.lineSeparator() + System.lineSeparator() + "some text" + System.lineSeparator();
         final String actual = FileUtils.readFileToString(file, StandardCharsets.US_ASCII.name());
         assertEquals(expected, actual);
     }
@@ -3269,13 +3214,9 @@ public void testWriteLines_3arg_nullSeparator() throws Exception {
     public void testWriteLines_3argsWithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...", StandardCharsets.UTF_8);
-
         final List<String> linesToAppend = Arrays.asList("my first line", "The second Line");
         FileUtils.writeLines(file, linesToAppend, false);
-
-        final String expected = "my first line"
-                + System.lineSeparator() + "The second Line"
-                + System.lineSeparator();
+        final String expected = "my first line" + System.lineSeparator() + "The second Line" + System.lineSeparator();
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
     }
@@ -3443,11 +3384,8 @@ public void testWriteStringToFile_WithAppendOptionFalse_ShouldDeletePreviousFile
     public void testWriteStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.writeStringToFile(file, "this is brand new data", true);
-
-        final String expected = "This line was there before you..."
-                + "this is brand new data";
+        final String expected = "This line was there before you...this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
     }
@@ -3488,9 +3426,7 @@ public void testWriteStringToFileWithCharset() throws Exception {
     public void testWriteStringToFileWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.writeStringToFile(file, "this is brand new data", (String) null, false);
-
         final String expected = "this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
@@ -3500,11 +3436,8 @@ public void testWriteStringToFileWithEncoding_WithAppendOptionFalse_ShouldDelete
     public void testWriteStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...");
-
         FileUtils.writeStringToFile(file, "this is brand new data", (String) null, true);
-
-        final String expected = "This line was there before you..."
-                + "this is brand new data";
+        final String expected = "This line was there before you...this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
     }
@@ -3529,9 +3462,7 @@ public void testWriteStringToFileWithNullStringCharset() throws Exception {
     public void testWriteWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...", StandardCharsets.UTF_8);
-
         FileUtils.write(file, "this is brand new data", (String) null, false);
-
         final String expected = "this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
@@ -3541,11 +3472,8 @@ public void testWriteWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFile
     public void testWriteWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         FileUtils.writeStringToFile(file, "This line was there before you...", StandardCharsets.UTF_8);
-
         FileUtils.write(file, "this is brand new data", (String) null, true);
-
-        final String expected = "This line was there before you..."
-                + "this is brand new data";
+        final String expected = "This line was there before you...this is brand new data";
         final String actual = FileUtils.readFileToString(file);
         assertEquals(expected, actual);
     }