@@ -2825,57 +2825,43 @@ public void testReadLines_IOExceptionOnPosixFileSystem() throws Exception {
28252825 final File file = TestUtils .newFile (tempDirFile , "cant-read.txt" );
28262826 TestUtils .createFile (file , 100 );
28272827 Files .setPosixFilePermissions (file .toPath (), PosixFilePermissions .fromString ("---------" ));
2828-
28292828 assertThrows (IOException .class , () -> FileUtils .readLines (file ));
28302829 }
28312830
28322831 @ Test
28332832 public void testSizeOf () throws Exception {
28342833 final File file = new File (tempDirFile , getName ());
2835-
28362834 // Null argument
28372835 assertThrows (NullPointerException .class , () -> FileUtils .sizeOf (null ));
2838-
28392836 // Non-existent file
28402837 assertThrows (IllegalArgumentException .class , () -> FileUtils .sizeOf (file ));
2841-
28422838 // Creates file
28432839 file .createNewFile ();
2844-
28452840 // New file
28462841 assertEquals (0 , FileUtils .sizeOf (file ));
28472842 file .delete ();
2848-
28492843 // Existing file
28502844 assertEquals (testFile1Size , FileUtils .sizeOf (testFile1 ), "Unexpected files size" );
2851-
28522845 // Existing directory
28532846 assertEquals (TEST_DIRECTORY_SIZE , FileUtils .sizeOf (tempDirFile ), "Unexpected directory size" );
28542847 }
28552848
28562849 @ Test
28572850 public void testSizeOfAsBigInteger () throws Exception {
28582851 final File file = new File (tempDirFile , getName ());
2859-
28602852 // Null argument
28612853 assertThrows (NullPointerException .class , () -> FileUtils .sizeOfAsBigInteger (null ));
28622854 // Non-existent file
28632855 assertThrows (IllegalArgumentException .class , () -> FileUtils .sizeOfAsBigInteger (file ));
2864-
28652856 // Creates file
28662857 file .createNewFile ();
2867-
28682858 // New file
28692859 assertEquals (BigInteger .ZERO , FileUtils .sizeOfAsBigInteger (file ));
28702860 file .delete ();
2871-
28722861 // Existing file
2873- assertEquals (BigInteger .valueOf (testFile1Size ), FileUtils .sizeOfAsBigInteger (testFile1 ),
2874- "Unexpected files size" );
2875-
2862+ assertEquals (BigInteger .valueOf (testFile1Size ), FileUtils .sizeOfAsBigInteger (testFile1 ), "Unexpected files size" );
28762863 // Existing directory
2877- assertEquals (TEST_DIRECTORY_SIZE_BI , FileUtils .sizeOfAsBigInteger (tempDirFile ),
2878- "Unexpected directory size" );
2864+ assertEquals (TEST_DIRECTORY_SIZE_BI , FileUtils .sizeOfAsBigInteger (tempDirFile ), "Unexpected directory size" );
28792865 }
28802866
28812867 /**
@@ -2888,25 +2874,19 @@ public void testSizeOfAsBigInteger() throws Exception {
28882874 @ Test
28892875 public void testSizeOfDirectory () throws Exception {
28902876 final File file = new File (tempDirFile , getName ());
2891-
28922877 // Null argument
28932878 assertThrows (NullPointerException .class , () -> FileUtils .sizeOfDirectory (null ));
28942879 // Non-existent file
28952880 assertThrows (IllegalArgumentException .class , () -> FileUtils .sizeOfAsBigInteger (file ));
2896-
28972881 // Creates file
28982882 file .createNewFile ();
2899-
29002883 // Existing file
29012884 assertThrows (IllegalArgumentException .class , () -> FileUtils .sizeOfDirectory (file ));
2902-
29032885 // Existing directory
29042886 file .delete ();
29052887 file .mkdir ();
2906-
29072888 // Create a cyclic symlink
29082889 createCircularSymbolicLink (file );
2909-
29102890 assertEquals (TEST_DIRECTORY_SIZE , FileUtils .sizeOfDirectory (file ), "Unexpected directory size" );
29112891 }
29122892
@@ -2920,30 +2900,22 @@ public void testSizeOfDirectory() throws Exception {
29202900 @ Test
29212901 public void testSizeOfDirectoryAsBigInteger () throws Exception {
29222902 final File file = new File (tempDirFile , getName ());
2923-
29242903 // Null argument
29252904 assertThrows (NullPointerException .class , () -> FileUtils .sizeOfDirectoryAsBigInteger (null ));
29262905 // Non-existent file
29272906 assertThrows (UncheckedIOException .class , () -> FileUtils .sizeOfDirectoryAsBigInteger (file ));
2928-
29292907 // Creates file
29302908 file .createNewFile ();
2931-
29322909 // Existing file
29332910 assertThrows (IllegalArgumentException .class , () -> FileUtils .sizeOfDirectoryAsBigInteger (file ));
2934-
29352911 // Existing directory
29362912 file .delete ();
29372913 file .mkdir ();
2938-
29392914 createCircularSymbolicLink (file );
2940-
29412915 assertEquals (TEST_DIRECTORY_SIZE_BI , FileUtils .sizeOfDirectoryAsBigInteger (file ), "Unexpected directory size" );
2942-
29432916 // Existing directory which size is greater than zero
29442917 file .delete ();
29452918 file .mkdir ();
2946-
29472919 final File nonEmptyFile = new File (file , "non-emptyFile" + System .nanoTime ());
29482920 assertTrue (nonEmptyFile .getParentFile ().exists (), () -> "Cannot create file " + nonEmptyFile + " as the parent directory does not exist" );
29492921 final OutputStream output = new BufferedOutputStream (Files .newOutputStream (nonEmptyFile .toPath ()));
@@ -2952,9 +2924,7 @@ public void testSizeOfDirectoryAsBigInteger() throws Exception {
29522924 } finally {
29532925 IOUtils .closeQuietly (output );
29542926 }
2955-
29562927 assertEquals (TEST_DIRECTORY_SIZE_GT_ZERO_BI , FileUtils .sizeOfDirectoryAsBigInteger (file ), "Unexpected directory size" );
2957-
29582928 nonEmptyFile .delete ();
29592929 file .delete ();
29602930 }
@@ -3055,7 +3025,6 @@ public void testToFileUtf8() throws Exception {
30553025 @ Test
30563026 public void testTouch () throws IOException {
30573027 assertThrows (NullPointerException .class , () -> FileUtils .touch (null ));
3058-
30593028 final File file = new File (tempDirFile , "touch.txt" );
30603029 if (file .exists ()) {
30613030 file .delete ();
@@ -3069,7 +3038,7 @@ public void testTouch() throws IOException {
30693038 }
30703039 assertEquals (1 , file .length (), "Wrote one byte to file" );
30713040 final long y2k = new GregorianCalendar (2000 , 0 , 1 ).getTime ().getTime ();
3072- final boolean res = setLastModifiedMillis (file , y2k ); // 0L fails on Win98
3041+ final boolean res = setLastModifiedMillis (file , y2k ); // 0L fails on Win98
30733042 assertTrue (res , "Bad test: set lastModified failed" );
30743043 assertEquals (y2k , getLastModifiedMillis (file ), "Bad test: set lastModified set incorrect value" );
30753044 final long nowMillis = System .currentTimeMillis ();
@@ -3116,36 +3085,28 @@ public void testToURLs1() throws Exception {
31163085
31173086 @ Test
31183087 public void testToURLs2 () {
3119- final File [] files = {
3120- new File (tempDirFile , "file1.txt" ),
3121- null ,
3122- };
3123- assertThrows (NullPointerException .class , () -> FileUtils .toURLs (files ),
3124- "Can't convert null URL" );
3088+ final File [] files = { new File (tempDirFile , "file1.txt" ), null , };
3089+ assertThrows (NullPointerException .class , () -> FileUtils .toURLs (files ), "Can't convert null URL" );
31253090 }
31263091
31273092 @ Test
31283093 public void testToURLs3 () {
31293094 final File [] files = null ;
3130- assertThrows (NullPointerException .class , () -> FileUtils .toURLs (files ),
3131- "Can't convert null list" );
3095+ assertThrows (NullPointerException .class , () -> FileUtils .toURLs (files ), "Can't convert null list" );
31323096 }
31333097
31343098 @ Test
31353099 public void testToURLs3a () throws Exception {
31363100 final File [] files = {}; // empty array
31373101 final URL [] urls = FileUtils .toURLs (files );
3138-
31393102 assertEquals (0 , urls .length );
31403103 }
31413104
31423105 @ Test
31433106 public void testWrite_WithAppendOptionFalse_ShouldDeletePreviousFileLines () throws Exception {
31443107 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
31453108 FileUtils .writeStringToFile (file , "This line was there before you..." );
3146-
31473109 FileUtils .write (file , "this is brand new data" , false );
3148-
31493110 final String expected = "this is brand new data" ;
31503111 final String actual = FileUtils .readFileToString (file );
31513112 assertEquals (expected , actual );
@@ -3155,11 +3116,8 @@ public void testWrite_WithAppendOptionFalse_ShouldDeletePreviousFileLines() thro
31553116 public void testWrite_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines () throws Exception {
31563117 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
31573118 FileUtils .writeStringToFile (file , "This line was there before you..." );
3158-
31593119 FileUtils .write (file , "this is brand new data" , true );
3160-
3161- final String expected = "This line was there before you..."
3162- + "this is brand new data" ;
3120+ final String expected = "This line was there before you...this is brand new data" ;
31633121 final String actual = FileUtils .readFileToString (file );
31643122 assertEquals (expected , actual );
31653123 }
@@ -3176,9 +3134,7 @@ public void testWriteByteArrayToFile() throws Exception {
31763134 public void testWriteByteArrayToFile_WithAppendOptionFalse_ShouldDeletePreviousFileLines () throws Exception {
31773135 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
31783136 FileUtils .writeStringToFile (file , "This line was there before you..." );
3179-
31803137 FileUtils .writeByteArrayToFile (file , "this is brand new data" .getBytes (), false );
3181-
31823138 final String expected = "this is brand new data" ;
31833139 final String actual = FileUtils .readFileToString (file );
31843140 assertEquals (expected , actual );
@@ -3188,11 +3144,8 @@ public void testWriteByteArrayToFile_WithAppendOptionFalse_ShouldDeletePreviousF
31883144 public void testWriteByteArrayToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines () throws Exception {
31893145 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
31903146 FileUtils .writeStringToFile (file , "This line was there before you..." );
3191-
31923147 FileUtils .writeByteArrayToFile (file , "this is brand new data" .getBytes (), true );
3193-
3194- final String expected = "This line was there before you..."
3195- + "this is brand new data" ;
3148+ final String expected = "This line was there before you...this is brand new data" ;
31963149 final String actual = FileUtils .readFileToString (file );
31973150 assertEquals (expected , actual );
31983151 }
@@ -3211,10 +3164,8 @@ public void testWriteByteArrayToFile_WithOffsetAndLength() throws Exception {
32113164 public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_ShouldDeletePreviousFileLines () throws Exception {
32123165 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
32133166 FileUtils .writeStringToFile (file , "This line was there before you..." );
3214-
32153167 final byte [] data = "SKIP_THIS_this is brand new data_AND_SKIP_THIS" .getBytes (StandardCharsets .UTF_8 );
32163168 FileUtils .writeByteArrayToFile (file , data , 10 , 22 , false );
3217-
32183169 final String expected = "this is brand new data" ;
32193170 final String actual = FileUtils .readFileToString (file , StandardCharsets .UTF_8 );
32203171 assertEquals (expected , actual );
@@ -3224,10 +3175,8 @@ public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_Sh
32243175 public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines () throws Exception {
32253176 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
32263177 FileUtils .writeStringToFile (file , "This line was there before you..." );
3227-
32283178 final byte [] data = "SKIP_THIS_this is brand new data_AND_SKIP_THIS" .getBytes (StandardCharsets .UTF_8 );
32293179 FileUtils .writeByteArrayToFile (file , data , 10 , 22 , true );
3230-
32313180 final String expected = "This line was there before you..." + "this is brand new data" ;
32323181 final String actual = FileUtils .readFileToString (file , StandardCharsets .UTF_8 );
32333182 assertEquals (expected , actual );
@@ -3251,16 +3200,12 @@ public void testWriteCharSequence2() throws Exception {
32513200
32523201 @ Test
32533202 public void testWriteLines_3arg_nullSeparator () throws Exception {
3254- final Object [] data = {
3255- "hello" , new StringBuffer ("world" ), "" , "this is" , null , "some text" };
3203+ final Object [] data = { "hello" , new StringBuffer ("world" ), "" , "this is" , null , "some text" };
32563204 final List <Object > list = Arrays .asList (data );
3257-
32583205 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
32593206 FileUtils .writeLines (file , StandardCharsets .US_ASCII .name (), list );
3260-
3261- final String expected = "hello" + System .lineSeparator () + "world" + System .lineSeparator () +
3262- System .lineSeparator () + "this is" + System .lineSeparator () +
3263- System .lineSeparator () + "some text" + System .lineSeparator ();
3207+ final String expected = "hello" + System .lineSeparator () + "world" + System .lineSeparator () + System .lineSeparator () + "this is"
3208+ + System .lineSeparator () + System .lineSeparator () + "some text" + System .lineSeparator ();
32643209 final String actual = FileUtils .readFileToString (file , StandardCharsets .US_ASCII .name ());
32653210 assertEquals (expected , actual );
32663211 }
@@ -3269,13 +3214,9 @@ public void testWriteLines_3arg_nullSeparator() throws Exception {
32693214 public void testWriteLines_3argsWithAppendOptionFalse_ShouldDeletePreviousFileLines () throws Exception {
32703215 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
32713216 FileUtils .writeStringToFile (file , "This line was there before you..." , StandardCharsets .UTF_8 );
3272-
32733217 final List <String > linesToAppend = Arrays .asList ("my first line" , "The second Line" );
32743218 FileUtils .writeLines (file , linesToAppend , false );
3275-
3276- final String expected = "my first line"
3277- + System .lineSeparator () + "The second Line"
3278- + System .lineSeparator ();
3219+ final String expected = "my first line" + System .lineSeparator () + "The second Line" + System .lineSeparator ();
32793220 final String actual = FileUtils .readFileToString (file );
32803221 assertEquals (expected , actual );
32813222 }
@@ -3443,11 +3384,8 @@ public void testWriteStringToFile_WithAppendOptionFalse_ShouldDeletePreviousFile
34433384 public void testWriteStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines () throws Exception {
34443385 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
34453386 FileUtils .writeStringToFile (file , "This line was there before you..." );
3446-
34473387 FileUtils .writeStringToFile (file , "this is brand new data" , true );
3448-
3449- final String expected = "This line was there before you..."
3450- + "this is brand new data" ;
3388+ final String expected = "This line was there before you...this is brand new data" ;
34513389 final String actual = FileUtils .readFileToString (file );
34523390 assertEquals (expected , actual );
34533391 }
@@ -3488,9 +3426,7 @@ public void testWriteStringToFileWithCharset() throws Exception {
34883426 public void testWriteStringToFileWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFileLines () throws Exception {
34893427 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
34903428 FileUtils .writeStringToFile (file , "This line was there before you..." );
3491-
34923429 FileUtils .writeStringToFile (file , "this is brand new data" , (String ) null , false );
3493-
34943430 final String expected = "this is brand new data" ;
34953431 final String actual = FileUtils .readFileToString (file );
34963432 assertEquals (expected , actual );
@@ -3500,11 +3436,8 @@ public void testWriteStringToFileWithEncoding_WithAppendOptionFalse_ShouldDelete
35003436 public void testWriteStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines () throws Exception {
35013437 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
35023438 FileUtils .writeStringToFile (file , "This line was there before you..." );
3503-
35043439 FileUtils .writeStringToFile (file , "this is brand new data" , (String ) null , true );
3505-
3506- final String expected = "This line was there before you..."
3507- + "this is brand new data" ;
3440+ final String expected = "This line was there before you...this is brand new data" ;
35083441 final String actual = FileUtils .readFileToString (file );
35093442 assertEquals (expected , actual );
35103443 }
@@ -3529,9 +3462,7 @@ public void testWriteStringToFileWithNullStringCharset() throws Exception {
35293462 public void testWriteWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFileLines () throws Exception {
35303463 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
35313464 FileUtils .writeStringToFile (file , "This line was there before you..." , StandardCharsets .UTF_8 );
3532-
35333465 FileUtils .write (file , "this is brand new data" , (String ) null , false );
3534-
35353466 final String expected = "this is brand new data" ;
35363467 final String actual = FileUtils .readFileToString (file );
35373468 assertEquals (expected , actual );
@@ -3541,11 +3472,8 @@ public void testWriteWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFile
35413472 public void testWriteWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines () throws Exception {
35423473 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
35433474 FileUtils .writeStringToFile (file , "This line was there before you..." , StandardCharsets .UTF_8 );
3544-
35453475 FileUtils .write (file , "this is brand new data" , (String ) null , true );
3546-
3547- final String expected = "This line was there before you..."
3548- + "this is brand new data" ;
3476+ final String expected = "This line was there before you...this is brand new data" ;
35493477 final String actual = FileUtils .readFileToString (file );
35503478 assertEquals (expected , actual );
35513479 }
0 commit comments