@@ -2148,36 +2148,28 @@ public void testIterateFilesAndDirs() throws IOException {
21482148 assertTrue (subDir3 .mkdir ());
21492149 assertTrue (subDir4 .mkdir ());
21502150 final File someFile = new File (subDir2 , "a.txt" );
2151- final WildcardFileFilter fileFilterAllFiles = WildcardFileFilter .builder ().setWildcards ("*.*" ).get ();
2151+ final WildcardFileFilter fileFilterAllFiles = WildcardFileFilter .builder ().setWildcards ("*.*" ).get ();
21522152 final WildcardFileFilter fileFilterAllDirs = WildcardFileFilter .builder ().setWildcards ("*" ).get ();
21532153 final WildcardFileFilter fileFilterExtTxt = WildcardFileFilter .builder ().setWildcards ("*.txt" ).get ();
2154- try {
2155- try (OutputStream output = new BufferedOutputStream (Files .newOutputStream (someFile .toPath ()))) {
2156- TestUtils .generateTestData (output , 100 );
2157- }
2158- //
2159- // "*.*" and "*"
2160- Collection <File > expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile , subDir3 , subDir4 );
2161- iterateFilesAndDirs (subDir1 , fileFilterAllFiles , fileFilterAllDirs , expectedFilesAndDirs );
2162- //
2163- // "*.txt" and "*"
2164- expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile , subDir3 , subDir4 );
2165- iterateFilesAndDirs (subDir1 , fileFilterExtTxt , fileFilterAllDirs , expectedFilesAndDirs );
2166- //
2167- // "*.*" and "subdir2"
2168- expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile );
2169- iterateFilesAndDirs (subDir1 , fileFilterAllFiles , new NameFileFilter ("subdir2" ), expectedFilesAndDirs );
2170- //
2171- // "*.txt" and "subdir2"
2172- expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile );
2173- iterateFilesAndDirs (subDir1 , fileFilterExtTxt , new NameFileFilter ("subdir2" ), expectedFilesAndDirs );
2174- } finally {
2175- someFile .delete ();
2176- subDir4 .delete ();
2177- subDir3 .delete ();
2178- subDir2 .delete ();
2179- subDir1 .delete ();
2154+ try (OutputStream output = new BufferedOutputStream (Files .newOutputStream (someFile .toPath ()))) {
2155+ TestUtils .generateTestData (output , 100 );
21802156 }
2157+ //
2158+ // "*.*" and "*"
2159+ Collection <File > expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile , subDir3 , subDir4 );
2160+ iterateFilesAndDirs (subDir1 , fileFilterAllFiles , fileFilterAllDirs , expectedFilesAndDirs );
2161+ //
2162+ // "*.txt" and "*"
2163+ expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile , subDir3 , subDir4 );
2164+ iterateFilesAndDirs (subDir1 , fileFilterExtTxt , fileFilterAllDirs , expectedFilesAndDirs );
2165+ //
2166+ // "*.*" and "subdir2"
2167+ expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile );
2168+ iterateFilesAndDirs (subDir1 , fileFilterAllFiles , new NameFileFilter ("subdir2" ), expectedFilesAndDirs );
2169+ //
2170+ // "*.txt" and "subdir2"
2171+ expectedFilesAndDirs = Arrays .asList (subDir1 , subDir2 , someFile );
2172+ iterateFilesAndDirs (subDir1 , fileFilterExtTxt , new NameFileFilter ("subdir2" ), expectedFilesAndDirs );
21812173 }
21822174
21832175 @ Test
@@ -2197,48 +2189,36 @@ public void testListFiles() throws Exception {
21972189 final File subDir2 = new File (subDir , "subdir" );
21982190 subDir .mkdir ();
21992191 subDir2 .mkdir ();
2200- try {
2201-
2202- final String [] expectedFileNames = { "a.txt" , "b.txt" , "c.txt" , "d.txt" , "e.txt" , "f.txt" };
2203- final int [] fileSizes = { 123 , 234 , 345 , 456 , 678 , 789 };
2204-
2205- for (int i = 0 ; i < expectedFileNames .length ; ++i ) {
2206- final File theFile = new File (subDir , expectedFileNames [i ]);
2207- if (!theFile .getParentFile ().exists ()) {
2208- fail ("Cannot create file " + theFile + " as the parent directory does not exist" );
2209- }
2210- try (BufferedOutputStream output = new BufferedOutputStream (Files .newOutputStream (theFile .toPath ()))) {
2211- TestUtils .generateTestData (output , fileSizes [i ]);
2212- }
2192+ final String [] expectedFileNames = { "a.txt" , "b.txt" , "c.txt" , "d.txt" , "e.txt" , "f.txt" };
2193+ final int [] fileSizes = { 123 , 234 , 345 , 456 , 678 , 789 };
2194+ for (int i = 0 ; i < expectedFileNames .length ; ++i ) {
2195+ final File theFile = new File (subDir , expectedFileNames [i ]);
2196+ if (!theFile .getParentFile ().exists ()) {
2197+ fail ("Cannot create file " + theFile + " as the parent directory does not exist" );
22132198 }
2214-
2215- // @formatter:off
2199+ try (BufferedOutputStream output = new BufferedOutputStream (Files .newOutputStream (theFile .toPath ()))) {
2200+ TestUtils .generateTestData (output , fileSizes [i ]);
2201+ }
2202+ }
2203+ // @formatter:off
22162204 final Collection <File > actualFiles = FileUtils .listFiles (subDir ,
22172205 WildcardFileFilter .builder ().setWildcards ("*.*" ).get (),
22182206 WildcardFileFilter .builder ().setWildcards ("*" ).get ());
22192207 // @formatter:on
2220-
2221- final int count = actualFiles .size ();
2222- final Object [] fileObjs = actualFiles .toArray ();
2223-
2224- assertEquals (expectedFileNames .length , actualFiles .size (), actualFiles ::toString );
2225-
2226- final Map <String , String > foundFileNames = new HashMap <>();
2227-
2228- for (int i = 0 ; i < count ; ++i ) {
2229- boolean found = false ;
2230- for (int j = 0 ; !found && j < expectedFileNames .length ; ++j ) {
2231- if (expectedFileNames [j ].equals (((File ) fileObjs [i ]).getName ())) {
2232- foundFileNames .put (expectedFileNames [j ], expectedFileNames [j ]);
2233- found = true ;
2234- }
2208+ final int count = actualFiles .size ();
2209+ final Object [] fileObjs = actualFiles .toArray ();
2210+ assertEquals (expectedFileNames .length , actualFiles .size (), actualFiles ::toString );
2211+ final Map <String , String > foundFileNames = new HashMap <>();
2212+ for (int i = 0 ; i < count ; ++i ) {
2213+ boolean found = false ;
2214+ for (int j = 0 ; !found && j < expectedFileNames .length ; ++j ) {
2215+ if (expectedFileNames [j ].equals (((File ) fileObjs [i ]).getName ())) {
2216+ foundFileNames .put (expectedFileNames [j ], expectedFileNames [j ]);
2217+ found = true ;
22352218 }
22362219 }
2237-
2238- assertEquals (foundFileNames .size (), expectedFileNames .length , foundFileNames ::toString );
2239- } finally {
2240- subDir .delete ();
22412220 }
2221+ assertEquals (foundFileNames .size (), expectedFileNames .length , foundFileNames ::toString );
22422222 }
22432223
22442224 @ Test
@@ -2256,37 +2236,29 @@ public void testListFilesOnlyNoDirs() throws IOException {
22562236 @ Test
22572237 public void testListFilesWithDirs () throws IOException {
22582238 final File srcDir = tempDirFile ;
2259-
22602239 final File subDir1 = new File (srcDir , "subdir" );
22612240 final File subDir2 = new File (subDir1 , "subdir2" );
22622241 subDir1 .mkdir ();
22632242 subDir2 .mkdir ();
2264- try {
2265- final File someFile = new File (subDir2 , "a.txt" );
2266- if (!someFile .getParentFile ().exists ()) {
2267- fail ("Cannot create file " + someFile + " as the parent directory does not exist" );
2268- }
2269- try (BufferedOutputStream output = new BufferedOutputStream (Files .newOutputStream (someFile .toPath ()))) {
2270- TestUtils .generateTestData (output , 100 );
2271- }
2272-
2273- final File subDir3 = new File (subDir2 , "subdir3" );
2274- subDir3 .mkdir ();
2275-
2276- // @formatter:off
2243+ final File someFile = new File (subDir2 , "a.txt" );
2244+ if (!someFile .getParentFile ().exists ()) {
2245+ fail ("Cannot create file " + someFile + " as the parent directory does not exist" );
2246+ }
2247+ try (BufferedOutputStream output = new BufferedOutputStream (Files .newOutputStream (someFile .toPath ()))) {
2248+ TestUtils .generateTestData (output , 100 );
2249+ }
2250+ final File subDir3 = new File (subDir2 , "subdir3" );
2251+ subDir3 .mkdir ();
2252+ // @formatter:off
22772253 final Collection <File > files = FileUtils .listFilesAndDirs (subDir1 ,
22782254 WildcardFileFilter .builder ().setWildcards ("*.*" ).get (),
22792255 WildcardFileFilter .builder ().setWildcards ("*" ).get ());
22802256 // @formatter:on
2281-
2282- assertEquals (4 , files .size ());
2283- assertTrue (files .contains (subDir1 ), "Should contain the directory." );
2284- assertTrue (files .contains (subDir2 ), "Should contain the directory." );
2285- assertTrue (files .contains (someFile ), "Should contain the file." );
2286- assertTrue (files .contains (subDir3 ), "Should contain the directory." );
2287- } finally {
2288- subDir1 .delete ();
2289- }
2257+ assertEquals (4 , files .size ());
2258+ assertTrue (files .contains (subDir1 ), "Should contain the directory." );
2259+ assertTrue (files .contains (subDir2 ), "Should contain the directory." );
2260+ assertTrue (files .contains (someFile ), "Should contain the file." );
2261+ assertTrue (files .contains (subDir3 ), "Should contain the directory." );
22902262 }
22912263
22922264 @ Test
@@ -2351,7 +2323,7 @@ public void testMoveDirectory_Errors() throws Exception {
23512323 }
23522324
23532325 @ Test
2354- public void testMoveDirectory_Rename () throws Exception {
2326+ public void testMoveDirectoryRename () throws Exception {
23552327 final File dir = tempDirFile ;
23562328 final File src = new File (dir , "testMoveDirectory1Source" );
23572329 final File testDir = new File (src , "foo" );
@@ -2412,7 +2384,7 @@ public void testMoveDirectoryToDirectory() throws Exception {
24122384 }
24132385
24142386 @ Test
2415- public void testMoveDirectoryToDirectory_Errors () throws Exception {
2387+ public void testMoveDirectoryToDirectoryErrors () throws Exception {
24162388 assertThrows (NullPointerException .class , () -> FileUtils .moveDirectoryToDirectory (null , new File ("foo" ), true ));
24172389 assertThrows (NullPointerException .class , () -> FileUtils .moveDirectoryToDirectory (new File ("foo" ), null , true ));
24182390 final File testFile1 = new File (tempDirFile , "testMoveFileFile1" );
@@ -2592,7 +2564,7 @@ public void testMoveFileToDirectory() throws Exception {
25922564 }
25932565
25942566 @ Test
2595- public void testMoveFileToDirectory_Errors () throws Exception {
2567+ public void testMoveFileToDirectoryErrors () throws Exception {
25962568 assertThrows (NullPointerException .class , () -> FileUtils .moveFileToDirectory (null , new File ("foo" ), true ));
25972569 assertThrows (NullPointerException .class , () -> FileUtils .moveFileToDirectory (new File ("foo" ), null , true ));
25982570 final File testFile1 = new File (tempDirFile , "testMoveFileFile1" );
@@ -2818,39 +2790,29 @@ public void testReadFileToStringWithEncoding() throws Exception {
28182790 }
28192791
28202792 @ Test
2821- public void testReadLines () throws Exception {
2793+ public void testReadLinesUTF8 () throws Exception {
28222794 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
2823- try {
2824- final String [] data = { "hello" , "\u1234 " , "" , "this is" , "some text" };
2825- TestUtils .createLineFileUtf8 (file , data );
2826- List <String > lines = FileUtils .readLines (file , UTF_8 );
2827- assertEquals (Arrays .asList (data ), lines );
2828- lines = FileUtils .readLines (file , (Charset ) null );
2829- assertEquals (Arrays .asList (data ), lines );
2830- } finally {
2831- TestUtils .deleteFile (file );
2832- }
2795+ final String [] data = { "hello" , "\u1234 " , "" , "this is" , "some text" };
2796+ TestUtils .createLineFileUtf8 (file , data );
2797+ final List <String > lines = FileUtils .readLines (file , UTF_8 );
2798+ assertEquals (Arrays .asList (data ), lines );
28332799 }
28342800
28352801 @ Test
28362802 public void testReadLinesDefaults () throws Exception {
28372803 final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
2838- try {
2839- final String [] data = { "hello" , "this is" , "some text" };
2840- TestUtils .createLineFileUtf8 (file , data );
2841- final List <String > lines1 = FileUtils .readLines (file );
2842- final List <String > lines2 = FileUtils .readLines (file , (Charset ) null );
2843- final List <String > lines3 = FileUtils .readLines (file , Charset .defaultCharset ());
2844- assertEquals (lines1 , Arrays .asList (data ));
2845- assertEquals (lines1 , lines2 );
2846- assertEquals (lines1 , lines3 );
2847- } finally {
2848- TestUtils .deleteFile (file );
2849- }
2804+ final String [] data = { "hello" , "this is" , "some text" };
2805+ TestUtils .createLineFileUtf8 (file , data );
2806+ final List <String > lines1 = FileUtils .readLines (file );
2807+ final List <String > lines2 = FileUtils .readLines (file , (Charset ) null );
2808+ final List <String > lines3 = FileUtils .readLines (file , Charset .defaultCharset ());
2809+ assertEquals (lines1 , Arrays .asList (data ));
2810+ assertEquals (lines1 , lines2 );
2811+ assertEquals (lines1 , lines3 );
28502812 }
28512813
28522814 @ Test
2853- public void testReadLines_Errors () {
2815+ public void testReadLinesErrors () {
28542816 assertThrows (NullPointerException .class , () -> FileUtils .readLines (null ));
28552817 assertThrows (IOException .class , () -> FileUtils .readLines (new File ("non-exsistent" )));
28562818 assertThrows (IOException .class , () -> FileUtils .readLines (tempDirFile ));
0 commit comments