View Javadoc
1   package org.apache.maven.shared.utils.io;
2   
3   import static org.hamcrest.CoreMatchers.containsString;
4   import static org.hamcrest.CoreMatchers.hasItems;
5   import static org.hamcrest.CoreMatchers.is;
6   import static org.hamcrest.CoreMatchers.not;
7   import static org.junit.Assert.assertFalse;
8   import static org.junit.Assert.assertThat;
9   import static org.junit.Assert.assertTrue;
10  import static org.junit.Assert.fail;
11  import static org.junit.Assume.assumeFalse;
12  import static org.junit.Assume.assumeThat;
13  import static org.junit.Assume.assumeTrue;
14  
15  import java.io.BufferedOutputStream;
16  import java.io.File;
17  import java.io.FileInputStream;
18  import java.io.FileNotFoundException;
19  import java.io.FileOutputStream;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.net.URL;
24  import java.util.Arrays;
25  import java.util.HashSet;
26  import java.util.List;
27  
28  /*
29   * Licensed to the Apache Software Foundation (ASF) under one
30   * or more contributor license agreements.  See the NOTICE file
31   * distributed with this work for additional information
32   * regarding copyright ownership.  The ASF licenses this file
33   * to you under the Apache License, Version 2.0 (the
34   * "License"); you may not use this file except in compliance
35   * with the License.  You may obtain a copy of the License at
36   *
37   *  http://www.apache.org/licenses/LICENSE-2.0
38   *
39   * Unless required by applicable law or agreed to in writing,
40   * software distributed under the License is distributed on an
41   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
42   * KIND, either express or implied.  See the License for the
43   * specific language governing permissions and limitations
44   * under the License.
45   */
46  
47  import org.apache.maven.shared.utils.Os;
48  import org.apache.maven.shared.utils.testhelpers.FileTestHelper;
49  import org.hamcrest.CoreMatchers;
50  import org.junit.Before;
51  import org.junit.Ignore;
52  import org.junit.Rule;
53  import org.junit.Test;
54  import org.junit.rules.TemporaryFolder;
55  import org.junit.rules.TestName;
56  
57  /**
58   * This is used to test FileUtils for correctness.
59   *
60   * @author Peter Donald
61   * @author Matthew Hawthorne
62   * @author Stephen Colebourne
63   * @author Jim Harrington
64   * @version $Id: FileUtilsTestCase.java 1081025 2011-03-13 00:45:10Z niallp $
65   * @see FileUtils
66   */
67  public class FileUtilsTest
68  {
69  
70      // Test data
71  
72      @Rule
73      public TemporaryFolder tempFolder = new TemporaryFolder();
74  
75      @Rule
76      public TestName name = new TestName();
77  
78      /**
79       * Size of test directory.
80       */
81      private static final int TEST_DIRECTORY_SIZE = 0;
82  
83      /**
84       * Delay in milliseconds to make sure test for "last modified date" are accurate
85       */
86      //private static final int LAST_MODIFIED_DELAY = 600;
87  
88      private File testFile1;
89  
90      private File testFile2;
91  
92      private long testFile1Size;
93  
94      private long testFile2Size;
95  
96      /**
97       * @see junit.framework.TestCase#setUp()
98       */
99      @Before
100     public void setUp()
101         throws Exception
102     {
103         testFile1 = tempFolder.newFile( "file1-test.txt" );
104         testFile2 = tempFolder.newFile( "file1a-test.txt" );
105 
106         testFile1Size = (int) testFile1.length();
107         testFile2Size = (int) testFile2.length();
108 
109         tempFolder.getRoot().mkdirs();
110         createFile( testFile1, testFile1Size );
111         createFile( testFile2, testFile2Size );
112         FileUtils.deleteDirectory( tempFolder.getRoot() );
113         tempFolder.getRoot().mkdirs();
114         createFile( testFile1, testFile1Size );
115         createFile( testFile2, testFile2Size );
116     }
117 
118     void createFile( File file, long size )
119         throws IOException
120     {
121         if ( !file.getParentFile().exists() )
122         {
123             throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" );
124         }
125         BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream( file ) );
126         try
127         {
128             FileTestHelper.generateTestData( output, size );
129         }
130         finally
131         {
132             IOUtil.close( output );
133         }
134     }
135 
136 
137     /**
138      * Assert that the content of a file is equal to that in a byte[].
139      */
140     void assertEqualContent( byte[] b0, File file )
141         throws IOException
142     {
143         InputStream is = new java.io.FileInputStream( file );
144         int count = 0, numRead = 0;
145         byte[] b1 = new byte[b0.length];
146         try
147         {
148             while ( count < b0.length && numRead >= 0 )
149             {
150                 numRead = is.read( b1, count, b0.length );
151                 count += numRead;
152             }
153             assertThat( "Different number of bytes: ", count, is( b0.length ) );
154             for ( int i = 0; i < count; i++ )
155             {
156                 assertThat( "byte " + i + " differs", b1[i], is( b0[i] ) );
157             }
158         }
159         finally
160         {
161             is.close();
162         }
163     }
164 
165     void deleteFile( File file )
166     {
167         if ( file.exists() )
168         {
169             assertThat( "Couldn't delete file: " + file, file.delete(), is( true ) );
170         }
171     }
172 
173 
174     //-----------------------------------------------------------------------
175     @Test
176     public void toFile1()
177         throws Exception
178     {
179         URL url = new URL( "file", null, "a/b/c/file.txt" );
180         File file = FileUtils.toFile( url );
181         assertThat( file.toString(), containsString( "file.txt" ) );
182     }
183 
184     @Test
185     public void toFile2()
186         throws Exception
187     {
188         URL url = new URL( "file", null, "a/b/c/file%20n%61me%2520.tx%74" );
189         File file = FileUtils.toFile( url );
190         assertThat( file.toString(), containsString( "file name%20.txt" ) );
191     }
192 
193     @Test
194     public void toFile3()
195         throws Exception
196     {
197         assertThat( FileUtils.toFile( null ), CoreMatchers.nullValue() );
198         assertThat( FileUtils.toFile( new URL( "http://jakarta.apache.org" ) ), CoreMatchers.nullValue() );
199     }
200 
201     @Test( expected = NumberFormatException.class )
202     public void toFile4()
203         throws Exception
204     {
205         URL url = new URL( "file", null, "a/b/c/file%%20%me.txt%" );
206         File file = FileUtils.toFile( url );
207         assertThat( file.toString(), containsString( "file% %me.txt%" ) );
208     }
209 
210     /**
211      * IO-252
212      */
213     @Test
214     public void toFile5()
215         throws Exception
216     {
217         URL url = new URL( "file", null, "both%20are%20100%20%25%20true" );
218         File file = FileUtils.toFile( url );
219         assertThat( file.toString(), is( "both are 100 % true" ) );
220     }
221 
222     @Test
223     public void toFileUtf8()
224         throws Exception
225     {
226         URL url = new URL( "file", null, "/home/%C3%A4%C3%B6%C3%BC%C3%9F" );
227         File file = FileUtils.toFile( url );
228         assertThat( file.toString(), not( containsString( "\u00E4\u00F6\u00FC\u00DF" ) ) );
229     }
230 
231     // toURLs
232 
233     @Test
234     public void toURLs1()
235         throws Exception
236     {
237         File[] files = new File[]{ new File( tempFolder.getRoot(), "file1.txt" ), new File( tempFolder.getRoot(), "file2.txt" ),
238             new File( tempFolder.getRoot(), "test file.txt" ), };
239         URL[] urls = FileUtils.toURLs( files );
240 
241         assertThat( urls.length, is( files.length ) );
242         assertThat( urls[0].toExternalForm().startsWith( "file:" ), is( true ) );
243         assertThat( urls[0].toExternalForm().contains( "file1.txt" ), is( true ) );
244         assertThat( urls[1].toExternalForm().startsWith( "file:" ), is( true ) );
245         assertThat( urls[1].toExternalForm(), containsString( "file2.txt" ) );
246 
247         // Test escaped char
248         assertThat( urls[2].toExternalForm().startsWith( "file:" ), is( true ) );
249         assertThat( urls[2].toExternalForm(), containsString( "test%20file.txt" ) );
250     }
251 
252 //    @Test public void toURLs2() throws Exception {
253 //        File[] files = new File[] {
254 //            new File(getTestDirectory(), "file1.txt"),
255 //            null,
256 //        };
257 //        URL[] urls = FileUtils.toURLs(files);
258 //
259 //        assertEquals(files.length, urls.length);
260 //        assertEquals(true, urls[0].toExternalForm().startsWith("file:"));
261 //        assertEquals(true, urls[0].toExternalForm().indexOf("file1.txt") > 0);
262 //        assertEquals(null, urls[1]);
263 //    }
264 //
265 //    @Test public void toURLs3() throws Exception {
266 //        File[] files = null;
267 //        URL[] urls = FileUtils.toURLs(files);
268 //
269 //        assertEquals(0, urls.length);
270 //    }
271 
272     // contentEquals
273 
274     @Test
275     public void contentEquals()
276         throws Exception
277     {
278         // Non-existent files
279         File file = new File( tempFolder.getRoot(), name.getMethodName() );
280         File file2 = new File( tempFolder.getRoot(), name.getMethodName() + "2" );
281         // both don't  exist
282         assertThat( FileUtils.contentEquals( file, file ), is( true ) );
283         assertThat( FileUtils.contentEquals( file, file2 ), is( true ) );
284         assertThat( FileUtils.contentEquals( file2, file2 ), is( true ) );
285         assertThat( FileUtils.contentEquals( file2, file ), is( true ) );
286 
287         // Directories
288         FileUtils.contentEquals( tempFolder.getRoot(), tempFolder.getRoot() );
289 
290         // Different files
291         File objFile1 = new File( tempFolder.getRoot(), name.getMethodName() + ".object" );
292         objFile1.deleteOnExit();
293         FileUtils.copyURLToFile( getClass().getResource( "/java/lang/Object.class" ), objFile1 );
294 
295         File objFile1b = new File( tempFolder.getRoot(), name.getMethodName() + ".object2" );
296         objFile1.deleteOnExit();
297         FileUtils.copyURLToFile( getClass().getResource( "/java/lang/Object.class" ), objFile1b );
298 
299         File objFile2 = new File( tempFolder.getRoot(), name.getMethodName() + ".collection" );
300         objFile2.deleteOnExit();
301         FileUtils.copyURLToFile( getClass().getResource( "/java/util/Collection.class" ), objFile2 );
302 
303         assertThat( FileUtils.contentEquals( objFile1, objFile2 ), is( false ) );
304         assertThat( FileUtils.contentEquals( objFile1b, objFile2 ), is( false ) );
305         assertThat( FileUtils.contentEquals( objFile1, objFile1b ), is( true ) );
306 
307         assertThat( FileUtils.contentEquals( objFile1, objFile1 ), is( true ) );
308         assertThat( FileUtils.contentEquals( objFile1b, objFile1b ), is( true ) );
309         assertThat( FileUtils.contentEquals( objFile2, objFile2 ), is( true ) );
310 
311         // Equal files
312         file.createNewFile();
313         file2.createNewFile();
314         assertThat( FileUtils.contentEquals( file, file ), is( true ) );
315         assertThat( FileUtils.contentEquals( file, file2 ), is( true ) );
316     }
317 
318     // copyURLToFile
319 
320     @Test
321     public void copyURLToFile()
322         throws Exception
323     {
324         // Creates file
325         File file = new File( tempFolder.getRoot(), name.getMethodName() );
326         file.deleteOnExit();
327 
328         // Loads resource
329         String resourceName = "/java/lang/Object.class";
330         FileUtils.copyURLToFile( getClass().getResource( resourceName ), file );
331 
332         // Tests that resuorce was copied correctly
333         FileInputStream fis = new FileInputStream( file );
334         try
335         {
336             assertThat( "Content is not equal.",
337                         IOUtil.contentEquals( getClass().getResourceAsStream( resourceName ), fis ), is( true ) );
338         }
339         finally
340         {
341             fis.close();
342         }
343         //TODO Maybe test copy to itself like for copyFile()
344     }
345 
346     // forceMkdir
347 
348     @Test
349     public void forceMkdir()
350         throws Exception
351     {
352         // Tests with existing directory
353         FileUtils.forceMkdir( tempFolder.getRoot() );
354 
355         // Creates test file
356         File testFile = new File( tempFolder.getRoot(), name.getMethodName() );
357         testFile.deleteOnExit();
358         testFile.createNewFile();
359         assertThat( "Test file does not exist.", testFile.exists(), is( true ) );
360 
361         // Tests with existing file
362         try
363         {
364             FileUtils.forceMkdir( testFile );
365             fail( "Exception expected." );
366         }
367         catch ( IOException ex )
368         {
369         }
370 
371         testFile.delete();
372 
373         // Tests with non-existent directory
374         FileUtils.forceMkdir( testFile );
375         assertThat( "Directory was not created.", testFile.exists(), is( true ) );
376     }
377 
378     // sizeOfDirectory
379 
380     @Test
381     public void sizeOfDirectory()
382         throws Exception
383     {
384         File file = new File( tempFolder.getRoot(), name.getMethodName() );
385 
386         // Non-existent file
387         try
388         {
389             FileUtils.sizeOfDirectory( file );
390             fail( "Exception expected." );
391         }
392         catch ( IllegalArgumentException ex )
393         {
394         }
395 
396         // Creates file
397         file.createNewFile();
398         file.deleteOnExit();
399 
400         // Existing file
401         try
402         {
403             FileUtils.sizeOfDirectory( file );
404             fail( "Exception expected." );
405         }
406         catch ( IllegalArgumentException ex )
407         {
408         }
409 
410         // Existing directory
411         file.delete();
412         file.mkdir();
413 
414         assertThat( "Unexpected directory size", FileUtils.sizeOfDirectory( file ), is( (long) TEST_DIRECTORY_SIZE ) );
415     }
416 
417     // copyFile
418 
419     @Test
420     public void copyFile1()
421         throws Exception
422     {
423         File destination = new File( tempFolder.getRoot(), "copy1.txt" );
424 
425         //Thread.sleep(LAST_MODIFIED_DELAY);
426         //This is to slow things down so we can catch if
427         //the lastModified date is not ok
428 
429         FileUtils.copyFile( testFile1, destination );
430         assertThat( "Check Exist", destination.exists(), is( true ) );
431         assertThat( "Check Full copy", destination.length(), is( testFile1Size ) );
432         /* disabled: Thread.sleep doesn't work reliantly for this case
433         assertTrue("Check last modified date preserved",
434             testFile1.lastModified() == destination.lastModified());*/
435     }
436 
437     @Test
438     public void copyFileThatIsSymlink()
439         throws Exception
440     {
441         assumeTrue( Java7Support.isAtLeastJava7() );
442         assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) );
443 
444         File destination = new File( tempFolder.getRoot(), "symCopy.txt" );
445 
446         File testDir = SymlinkTestSetup.createStandardSymlinkTestDir( new File( "target/test/symlinkCopy" ) );
447 
448         FileUtils.copyFile( new File( testDir, "symR" ), destination );
449         assertTrue( Java7Support.isSymLink(  destination ));
450     }
451 
452 
453 
454     @Test
455     public void deleteFile()
456         throws Exception
457     {
458         File destination = new File( tempFolder.getRoot(), "copy1.txt" );
459         FileUtils.copyFile( testFile1, destination );
460         FileUtils.delete( destination );
461         assertThat( "Check Exist", destination.exists(), is( false ) );
462     }
463 
464     @Test(expected = IOException.class)
465     public void deleteFileNofile()
466         throws Exception
467     {
468         File destination = new File( "abc/cde" );
469         FileUtils.delete( destination );
470     }
471 
472     @Test
473     public void deleteFileLegacy()
474         throws Exception
475     {
476         File destination = new File( tempFolder.getRoot(), "copy1.txt" );
477         FileUtils.copyFile( testFile1, destination );
478         assertTrue( FileUtils.deleteLegacyStyle( destination ) );
479     }
480 
481     @Test
482     public void deleteFileLegacyNofile()
483         throws Exception
484     {
485         File destination = new File( "abc/cde" );
486         assertFalse( FileUtils.deleteLegacyStyle( destination ) );
487     }
488 
489     @Test
490     public void copyFile2()
491         throws Exception
492     {
493         File destination = new File( tempFolder.getRoot(), "copy2.txt" );
494 
495         //Thread.sleep(LAST_MODIFIED_DELAY);
496         //This is to slow things down so we can catch if
497         //the lastModified date is not ok
498 
499         FileUtils.copyFile( testFile1, destination );
500         assertThat( "Check Exist", destination.exists(), is( true ) );
501         assertThat( "Check Full copy", destination.length(), is( testFile2Size ) );
502         /* disabled: Thread.sleep doesn't work reliably for this case
503         assertTrue("Check last modified date preserved",
504             testFile1.lastModified() == destination.lastModified());*/
505     }
506 
507     @Test
508     @Ignore( "Commons test case that is failing for plexus" )
509     public void copyToSelf()
510         throws Exception
511     {
512         File destination = new File( tempFolder.getRoot(), "copy3.txt" );
513         //Prepare a test file
514         FileUtils.copyFile( testFile1, destination );
515 
516         FileUtils.copyFile( destination, destination );
517     }
518 
519     @Test
520     @Ignore( "Commons test case that is failing for plexus" )
521     public void copyDirectoryToDirectory_NonExistingDest()
522         throws Exception
523     {
524         createFile( testFile1, 1234 );
525         createFile( testFile2, 4321 );
526         File srcDir = tempFolder.getRoot();
527         File subDir = new File( srcDir, "sub" );
528         subDir.mkdir();
529         File subFile = new File( subDir, "A.txt" );
530         FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" );
531         File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" );
532         FileUtils.deleteDirectory( destDir );
533         File actualDestDir = new File( destDir, srcDir.getName() );
534 
535         FileUtils.copyDirectory( srcDir, destDir );
536 
537         assertThat( "Check exists", destDir.exists(), is( true ) );
538         assertThat( "Check exists", actualDestDir.exists(), is( true ) );
539         assertThat( "Check size", FileUtils.sizeOfDirectory( actualDestDir ),
540                     is( FileUtils.sizeOfDirectory( srcDir ) ) );
541         assertThat( new File( actualDestDir, "sub/A.txt" ).exists(), is( true ) );
542         FileUtils.deleteDirectory( destDir );
543     }
544 
545     @Test
546     @Ignore( "Commons test case that is failing for plexus" )
547     public void copyDirectoryToNonExistingDest()
548         throws Exception
549     {
550         createFile( testFile1, 1234 );
551         createFile( testFile2, 4321 );
552         File srcDir = tempFolder.getRoot();
553         File subDir = new File( srcDir, "sub" );
554         subDir.mkdir();
555         File subFile = new File( subDir, "A.txt" );
556         FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" );
557         File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" );
558         FileUtils.deleteDirectory( destDir );
559 
560         FileUtils.copyDirectory( srcDir, destDir );
561 
562         assertThat( "Check exists", destDir.exists(), is( true ) );
563         assertThat( "Check size", FileUtils.sizeOfDirectory( destDir ), is( FileUtils.sizeOfDirectory( srcDir ) ) );
564         assertThat( new File( destDir, "sub/A.txt" ).exists(), is( true ) );
565         FileUtils.deleteDirectory( destDir );
566     }
567 
568     @Test
569     @Ignore( "Commons test case that is failing for plexus" )
570     public void copyDirectoryToExistingDest()
571         throws Exception
572     {
573         createFile( testFile1, 1234 );
574         createFile( testFile2, 4321 );
575         File srcDir = tempFolder.getRoot();
576         File subDir = new File( srcDir, "sub" );
577         subDir.mkdir();
578         File subFile = new File( subDir, "A.txt" );
579         FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" );
580         File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" );
581         FileUtils.deleteDirectory( destDir );
582         destDir.mkdirs();
583 
584         FileUtils.copyDirectory( srcDir, destDir );
585 
586         assertThat( FileUtils.sizeOfDirectory( destDir ), is( FileUtils.sizeOfDirectory( srcDir ) ) );
587         assertThat( new File( destDir, "sub/A.txt" ).exists(), is( true ) );
588     }
589 
590     /**
591      * Test for IO-141
592      */
593     @Test
594     @Ignore( "Commons test case that is failing for plexus" )
595     public void copyDirectoryToChild()
596         throws Exception
597     {
598         File grandParentDir = new File( tempFolder.getRoot(), "grandparent" );
599         File parentDir = new File( grandParentDir, "parent" );
600         File childDir = new File( parentDir, "child" );
601         createFilesForTestCopyDirectory( grandParentDir, parentDir, childDir );
602 
603         long expectedCount =
604             FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size()
605                 + FileUtils.getFileAndDirectoryNames( parentDir, null, null, true, true, true, true ).size();
606         long expectedSize = FileUtils.sizeOfDirectory( grandParentDir ) + FileUtils.sizeOfDirectory( parentDir );
607         FileUtils.copyDirectory( parentDir, childDir );
608         assertThat(
609             1L * FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size(),
610             is( expectedCount ) );
611         assertThat( FileUtils.sizeOfDirectory( grandParentDir ), is( expectedSize ) );
612     }
613 
614     /**
615      * Test for IO-141
616      */
617     @Test
618     @Ignore( "Commons test case that is failing for plexus" )
619     public void copyDirectoryToGrandChild()
620         throws Exception
621     {
622         File grandParentDir = new File( tempFolder.getRoot(), "grandparent" );
623         File parentDir = new File( grandParentDir, "parent" );
624         File childDir = new File( parentDir, "child" );
625         createFilesForTestCopyDirectory( grandParentDir, parentDir, childDir );
626 
627         long expectedCount =
628             ( FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size() * 2 );
629         long expectedSize = ( FileUtils.sizeOfDirectory( grandParentDir ) * 2 );
630         FileUtils.copyDirectory( grandParentDir, childDir );
631         assertThat(
632             1L * FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size(),
633             is( expectedCount ) );
634         assertThat( FileUtils.sizeOfDirectory( grandParentDir ), is( expectedSize ) );
635     }
636 
637     /**
638      * Test for IO-217 FileUtils.copyDirectoryToDirectory makes infinite loops
639      */
640     @Test
641     public void copyDirectoryToItself()
642         throws Exception
643     {
644         File dir = new File( tempFolder.getRoot(), "itself" );
645         dir.mkdirs();
646         FileUtils.copyDirectory( dir, dir );
647         assertThat( FileUtils.getFileAndDirectoryNames( dir, null, null, true, true, true, true ).size(), is( 1 ) );
648     }
649 
650     private void createFilesForTestCopyDirectory( File grandParentDir, File parentDir, File childDir )
651         throws Exception
652     {
653         File childDir2 = new File( parentDir, "child2" );
654         File grandChildDir = new File( childDir, "grandChild" );
655         File grandChild2Dir = new File( childDir2, "grandChild2" );
656         File file1 = new File( grandParentDir, "file1.txt" );
657         File file2 = new File( parentDir, "file2.txt" );
658         File file3 = new File( childDir, "file3.txt" );
659         File file4 = new File( childDir2, "file4.txt" );
660         File file5 = new File( grandChildDir, "file5.txt" );
661         File file6 = new File( grandChild2Dir, "file6.txt" );
662         FileUtils.deleteDirectory( grandParentDir );
663         grandChildDir.mkdirs();
664         grandChild2Dir.mkdirs();
665         FileUtils.fileWrite( file1, "UTF8", "File 1 in grandparent" );
666         FileUtils.fileWrite( file2, "UTF8", "File 2 in parent" );
667         FileUtils.fileWrite( file3, "UTF8", "File 3 in child" );
668         FileUtils.fileWrite( file4, "UTF8", "File 4 in child2" );
669         FileUtils.fileWrite( file5, "UTF8", "File 5 in grandChild" );
670         FileUtils.fileWrite( file6, "UTF8", "File 6 in grandChild2" );
671     }
672 
673     @Test
674     @Ignore( "Commons test case that is failing for plexus" )
675     public void copyDirectoryErrors()
676         throws Exception
677     {
678         try
679         {
680             FileUtils.copyDirectory( null, null );
681             fail();
682         }
683         catch ( NullPointerException ex )
684         {
685         }
686         try
687         {
688             FileUtils.copyDirectory( new File( "a" ), null );
689             fail();
690         }
691         catch ( NullPointerException ex )
692         {
693         }
694         try
695         {
696             FileUtils.copyDirectory( null, new File( "a" ) );
697             fail();
698         }
699         catch ( NullPointerException ex )
700         {
701         }
702         try
703         {
704             FileUtils.copyDirectory( new File( "doesnt-exist" ), new File( "a" ) );
705             fail();
706         }
707         catch ( IOException ex )
708         {
709         }
710         try
711         {
712             FileUtils.copyDirectory( testFile1, new File( "a" ) );
713             fail();
714         }
715         catch ( IOException ex )
716         {
717         }
718         try
719         {
720             FileUtils.copyDirectory( tempFolder.getRoot(), testFile1 );
721             fail();
722         }
723         catch ( IOException ex )
724         {
725         }
726         try
727         {
728             FileUtils.copyDirectory( tempFolder.getRoot(), tempFolder.getRoot() );
729             fail();
730         }
731         catch ( IOException ex )
732         {
733         }
734     }
735 
736     // forceDelete
737 
738     @Test
739     public void forceDeleteAFile1()
740         throws Exception
741     {
742         File destination = new File( tempFolder.getRoot(), "copy1.txt" );
743         destination.createNewFile();
744         assertThat( "Copy1.txt doesn't exist to delete", destination.exists(), is( true ) );
745         FileUtils.forceDelete( destination );
746         assertThat( "Check No Exist", !destination.exists(), is( true ) );
747     }
748 
749     @Test
750     public void forceDeleteAFile2()
751         throws Exception
752     {
753         File destination = new File( tempFolder.getRoot(), "copy2.txt" );
754         destination.createNewFile();
755         assertThat( "Copy2.txt doesn't exist to delete", destination.exists(), is( true ) );
756         FileUtils.forceDelete( destination );
757         assertThat( "Check No Exist", !destination.exists(), is( true ) );
758     }
759 
760     @Test
761     @Ignore( "Commons test case that is failing for plexus" )
762     public void forceDeleteAFile3()
763         throws Exception
764     {
765         File destination = new File( tempFolder.getRoot(), "no_such_file" );
766         assertThat( "Check No Exist", !destination.exists(), is( true ) );
767         try
768         {
769             FileUtils.forceDelete( destination );
770             fail( "Should generate FileNotFoundException" );
771         }
772         catch ( FileNotFoundException ignored )
773         {
774         }
775     }
776 
777     // copyFileToDirectory
778 
779     @Test
780     @Ignore( "Commons test case that is failing for plexus" )
781     public void copyFile1ToDir()
782         throws Exception
783     {
784         File directory = new File( tempFolder.getRoot(), "subdir" );
785         if ( !directory.exists() )
786         {
787             directory.mkdirs();
788         }
789         File destination = new File( directory, testFile1.getName() );
790 
791         //Thread.sleep(LAST_MODIFIED_DELAY);
792         //This is to slow things down so we can catch if
793         //the lastModified date is not ok
794 
795         FileUtils.copyFileToDirectory( testFile1, directory );
796         assertThat( "Check Exist", destination.exists(), is( true ) );
797         assertThat( "Check Full copy", destination.length(), is( testFile1Size ) );
798         /* disabled: Thread.sleep doesn't work reliantly for this case
799         assertTrue("Check last modified date preserved",
800             testFile1.lastModified() == destination.lastModified());*/
801 
802         try
803         {
804             FileUtils.copyFileToDirectory( destination, directory );
805             fail( "Should not be able to copy a file into the same directory as itself" );
806         }
807         catch ( IOException ioe )
808         {
809             //we want that, cannot copy to the same directory as the original file
810         }
811     }
812 
813     @Test
814     public void copyFile2ToDir()
815         throws Exception
816     {
817         File directory = new File( tempFolder.getRoot(), "subdir" );
818         if ( !directory.exists() )
819         {
820             directory.mkdirs();
821         }
822         File destination = new File( directory, testFile1.getName() );
823 
824         //Thread.sleep(LAST_MODIFIED_DELAY);
825         //This is to slow things down so we can catch if
826         //the lastModified date is not ok
827 
828         FileUtils.copyFileToDirectory( testFile1, directory );
829         assertThat( "Check Exist", destination.exists(), is( true ) );
830         assertThat( "Check Full copy", destination.length(), is( testFile2Size ) );
831         /* disabled: Thread.sleep doesn't work reliantly for this case
832         assertTrue("Check last modified date preserved",
833             testFile1.lastModified() == destination.lastModified());*/
834     }
835 
836     // forceDelete
837 
838     @Test
839     public void forceDeleteDir()
840         throws Exception
841     {
842         File testDirectory = tempFolder.newFolder( name.getMethodName() );
843         FileUtils.forceDelete( testDirectory.getParentFile() );
844         assertThat( "Check No Exist", !testDirectory.getParentFile().exists(), is( true ) );
845     }
846 
847     /**
848      * Test the FileUtils implementation.
849      */
850     @Test
851     public void fileUtils()
852         throws Exception
853     {
854         // Loads file from classpath
855         File file1 = new File( tempFolder.getRoot(), "test.txt" );
856         String filename = file1.getAbsolutePath();
857 
858         //Create test file on-the-fly (used to be in CVS)
859         OutputStream out = new java.io.FileOutputStream( file1 );
860         try
861         {
862             out.write( "This is a test".getBytes( "UTF-8" ) );
863         }
864         finally
865         {
866             out.close();
867         }
868 
869         File file2 = new File( tempFolder.getRoot(), "test2.txt" );
870 
871         FileUtils.fileWrite( file2, "UTF-8", filename );
872         assertThat( file2.exists(), is( true ) );
873         assertThat( file2.length() > 0, is( true ) );
874 
875         String file2contents = FileUtils.fileRead( file2, "UTF-8" );
876         assertThat( "Second file's contents correct", filename.equals( file2contents ), is( true ) );
877 
878         assertThat( file2.delete(), is( true ) );
879 
880         String contents = FileUtils.fileRead( new File( filename ), "UTF-8" );
881         assertThat( "FileUtils.fileRead()", contents.equals( "This is a test" ), is( true ) );
882 
883     }
884 
885     @Test
886     public void fileReadWithDefaultEncoding()
887         throws Exception
888     {
889         File file = new File( tempFolder.getRoot(), "read.obj" );
890         FileOutputStream out = new FileOutputStream( file );
891         byte[] text = "Hello /u1234".getBytes();
892         out.write( text );
893         out.close();
894 
895         String data = FileUtils.fileRead( file );
896         assertThat( data, is( "Hello /u1234" ) );
897     }
898 
899     @Test
900     public void fileReadWithEncoding()
901         throws Exception
902     {
903         File file = new File( tempFolder.getRoot(), "read.obj" );
904         FileOutputStream out = new FileOutputStream( file );
905         byte[] text = "Hello /u1234".getBytes( "UTF8" );
906         out.write( text );
907         out.close();
908 
909         String data = FileUtils.fileRead( file, "UTF8" );
910         assertThat( data, is( "Hello /u1234" ) );
911     }
912 
913     @Test
914     @Ignore( "Commons test case that is failing for plexus" )
915     public void readLines()
916         throws Exception
917     {
918         File file = FileTestHelper.newFile( tempFolder, "lines.txt" );
919         try
920         {
921             String[] data = new String[]{ "hello", "/u1234", "", "this is", "some text" };
922             FileTestHelper.createLineBasedFile( file, data );
923 
924             List<String> lines = FileUtils.loadFile( file );
925             assertThat( lines, is( Arrays.asList( data ) ) );
926         }
927         finally
928         {
929             deleteFile( file );
930         }
931     }
932 
933     @Test
934     public void writeStringToFile1()
935         throws Exception
936     {
937         File file = new File( tempFolder.getRoot(), "write.txt" );
938         FileUtils.fileWrite( file, "UTF8", "Hello /u1234" );
939         byte[] text = "Hello /u1234".getBytes( "UTF8" );
940         assertEqualContent( text, file );
941     }
942 
943     @Test
944     public void writeStringToFile2()
945         throws Exception
946     {
947         File file = new File( tempFolder.getRoot(), "write.txt" );
948         FileUtils.fileWrite( file, null, "Hello /u1234" );
949         byte[] text = "Hello /u1234".getBytes();
950         assertEqualContent( text, file );
951     }
952 
953     @Test
954     public void writeCharSequence1()
955         throws Exception
956     {
957         File file = new File( tempFolder.getRoot(), "write.txt" );
958         FileUtils.fileWrite( file, "UTF8", "Hello /u1234" );
959         byte[] text = "Hello /u1234".getBytes( "UTF8" );
960         assertEqualContent( text, file );
961     }
962 
963     @Test
964     public void writeCharSequence2()
965         throws Exception
966     {
967         File file = new File( tempFolder.getRoot(), "write.txt" );
968         FileUtils.fileWrite( file, null, "Hello /u1234" );
969         byte[] text = "Hello /u1234".getBytes();
970         assertEqualContent( text, file );
971     }
972 
973 
974     @Test
975     public void writeStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines()
976         throws Exception
977     {
978         File file = FileTestHelper.newFile( tempFolder, "lines.txt" );
979         FileUtils.fileWrite( file, null, "This line was there before you..." );
980 
981         FileUtils.fileAppend( file.getAbsolutePath(), "this is brand new data" );
982 
983         String expected = "This line was there before you..." + "this is brand new data";
984         String actual = FileUtils.fileRead( file );
985         assertThat( actual, is( expected ) );
986     }
987 
988     @Test
989     public void writeStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines()
990         throws Exception
991     {
992         File file = FileTestHelper.newFile( tempFolder, "lines.txt" );
993         FileUtils.fileWrite( file, null, "This line was there before you..." );
994 
995         FileUtils.fileAppend( file.getAbsolutePath(), "this is brand new data" );
996 
997         String expected = "This line was there before you..." + "this is brand new data";
998         String actual = FileUtils.fileRead( file );
999         assertThat( actual, is( expected ) );
1000     }
1001 
1002     @Test
1003     public void writeStringArrayToFile()
1004             throws Exception
1005     {
1006         File file = new File( tempFolder.getRoot(), "writeArray.txt" );
1007         FileUtils.fileWriteArray( file, new String[]{"line1", "line2", "line3"} );
1008 
1009         byte[] text = "line1\nline2\nline3".getBytes( "UTF8" );
1010         assertEqualContent( text, file );
1011     }
1012 
1013     @Test
1014     public void writeStringArrayToFileWithEncoding()
1015             throws Exception
1016     {
1017         File file = new File( tempFolder.getRoot(), "writeArray.txt" );
1018         FileUtils.fileWriteArray( file, "UTF8", new String[]{"line1", "line2", "line3"} );
1019 
1020         byte[] text = "line1\nline2\nline3".getBytes( "UTF8" );
1021         assertEqualContent( text, file );
1022     }
1023 
1024 
1025     @Test
1026     public void writeWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines()
1027         throws Exception
1028     {
1029         File file = FileTestHelper.newFile( tempFolder, "lines.txt" );
1030         FileUtils.fileWrite( file, "UTF-8", "This line was there before you..." );
1031 
1032         FileUtils.fileAppend( file.getAbsolutePath(), "UTF-8", "this is brand new data" );
1033 
1034         String expected = "This line was there before you..." + "this is brand new data";
1035         String actual = FileUtils.fileRead( file );
1036         assertThat( actual, is( expected ) );
1037     }
1038 
1039     @Test
1040     public void write_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines()
1041         throws Exception
1042     {
1043         File file = FileTestHelper.newFile( tempFolder, "lines.txt" );
1044         FileUtils.fileWrite( file, null, "This line was there before you..." );
1045 
1046         FileUtils.fileAppend( file.getAbsolutePath(), "this is brand new data" );
1047 
1048         String expected = "This line was there before you..." + "this is brand new data";
1049         String actual = FileUtils.fileRead( file );
1050         assertThat( actual, is( expected ) );
1051     }
1052 
1053     @Test( expected = NullPointerException.class )
1054     public void blowUpOnNull()
1055         throws IOException
1056     {
1057         FileUtils.deleteDirectory( (File) null );
1058     }
1059 
1060     @Test
1061     public void deleteQuietlyDir()
1062         throws IOException
1063     {
1064         File testDirectory = new File( tempFolder.getRoot(), "testDeleteQuietlyDir" );
1065         File testFile = new File( testDirectory, "testDeleteQuietlyFile" );
1066         testDirectory.mkdirs();
1067         createFile( testFile, 0 );
1068 
1069         assertThat( testDirectory.exists(), is( true ) );
1070         assertThat( testFile.exists(), is( true ) );
1071         FileUtils.deleteDirectory( testDirectory );
1072         assertThat( "Check No Exist", testDirectory.exists(), is( false ) );
1073         assertThat( "Check No Exist", testFile.exists(), is( false ) );
1074     }
1075 
1076     @Test
1077     public void deleteQuietlyFile()
1078         throws IOException
1079     {
1080         File testFile = new File( tempFolder.getRoot(), "testDeleteQuietlyFile" );
1081         createFile( testFile, 0 );
1082 
1083         assertThat( testFile.exists(), is( true ) );
1084         FileUtils.deleteDirectory( testFile );
1085         assertThat( "Check No Exist", testFile.exists(), is( false ) );
1086     }
1087 
1088     @Test
1089     public void deleteQuietlyNonExistent()
1090         throws IOException
1091     {
1092         File testFile = new File( tempFolder.getRoot(), "testDeleteQuietlyNonExistent" );
1093         assertThat( testFile.exists(), is( false ) );
1094 
1095         FileUtils.deleteDirectory( testFile );
1096     }
1097 
1098 
1099     ////  getDefaultExcludes
1100 
1101     @Test
1102     public void getDefaultExcludes()
1103         throws Exception
1104     {
1105         assertThat( Arrays.asList( FileUtils.getDefaultExcludes() ), hasItems( MINIMUM_DEFAULT_EXCLUDES ) );
1106     }
1107 
1108 
1109     //// getDefaultExcludesAsList
1110 
1111     @Test
1112     @SuppressWarnings( "unchecked" )
1113     public void getDefaultExcludesAsList()
1114         throws Exception
1115     {
1116         assertThat( FileUtils.getDefaultExcludesAsList(), hasItems( MINIMUM_DEFAULT_EXCLUDES ) );
1117     }
1118 
1119 
1120     //// getDefaultExcludesAsString
1121 
1122     @Test
1123     public void getDefaultExcludesAsString()
1124         throws Exception
1125     {
1126         assertThat( new HashSet<String>( Arrays.asList( FileUtils.getDefaultExcludesAsString().split( "," ) ) ),
1127                     hasItems( MINIMUM_DEFAULT_EXCLUDES ) );
1128     }
1129 
1130 
1131 
1132     //// dirname(String)
1133 
1134     @SuppressWarnings("ConstantConditions")
1135     @Test( expected = NullPointerException.class )
1136     public void nlowUpOnDirnameNull()
1137         throws Exception
1138     {
1139         FileUtils.dirname( null );
1140     }
1141 
1142     @Test
1143     public void dirnameEmpty()
1144         throws Exception
1145     {
1146         assertThat( FileUtils.dirname( "" ), is( "" ) );
1147     }
1148 
1149     @Test
1150     public void dirnameFilename()
1151         throws Exception
1152     {
1153         assertThat( FileUtils.dirname( "foo.bar.txt" ), is( "" ) );
1154     }
1155 
1156     @Test
1157     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1158     public void dirnameWindowsRootPathOnUnix()
1159         throws Exception
1160     {
1161         assumeThat( File.separatorChar, is( '/' ) );
1162         assertThat( FileUtils.dirname( "C:\\foo.bar.txt" ), is( "" ) );
1163     }
1164 
1165     @Test
1166     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1167     public void dirnameWindowsNonRootPathOnUnix()
1168         throws Exception
1169     {
1170         assumeThat( File.separatorChar, is( '/' ) );
1171         assertThat( FileUtils.dirname( "C:\\test\\foo.bar.txt" ), is( "" ) );
1172     }
1173 
1174     @Test
1175     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1176     public void dirnameUnixRootPathOnWindows()
1177         throws Exception
1178     {
1179         assumeThat( File.separatorChar, is( '\\' ) );
1180         assertThat( FileUtils.dirname( "/foo.bar.txt" ), is( "" ) );
1181     }
1182 
1183     @Test
1184     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1185     public void dirnameUnixNonRootPathOnWindows()
1186         throws Exception
1187     {
1188         assumeThat( File.separatorChar, is( '\\' ) );
1189         assertThat( FileUtils.dirname( "/test/foo.bar.txt" ), is( "" ) );
1190     }
1191 
1192     @Test
1193     public void dirnameWindowsRootPathOnWindows()
1194         throws Exception
1195     {
1196         assumeThat( File.separatorChar, is( '\\' ) );
1197         assertThat( FileUtils.dirname( "C:\\foo.bar.txt" ), is( "C:" ) );
1198     }
1199 
1200     @Test
1201     public void dirnameWindowsNonRootPathOnWindows()
1202         throws Exception
1203     {
1204         assumeThat( File.separatorChar, is( '\\' ) );
1205         assertThat( FileUtils.dirname( "C:\\test\\foo.bar.txt" ), is( "C:\\test" ) );
1206     }
1207 
1208     @Test
1209     public void dirnameUnixRootPathOnUnix()
1210         throws Exception
1211     {
1212         assumeThat( File.separatorChar, is( '/' ) );
1213         assertThat( FileUtils.dirname( "/foo.bar.txt" ), is( "" ) );
1214     }
1215 
1216     @Test
1217     public void dirnameUnixNonRootPathOnUnix()
1218         throws Exception
1219     {
1220         assumeThat( File.separatorChar, is( '/' ) );
1221         assertThat( FileUtils.dirname( "/test/foo.bar.txt" ), is( "/test" ) );
1222     }
1223 
1224     //// filename(String)
1225 
1226     @SuppressWarnings("ConstantConditions")
1227     @Test( expected = NullPointerException.class )
1228     public void blowUpOnFilenameNull()
1229         throws Exception
1230     {
1231         FileUtils.filename( null );
1232     }
1233 
1234     @Test
1235     public void filenameEmpty()
1236         throws Exception
1237     {
1238         assertThat( FileUtils.filename( "" ), is( "" ) );
1239     }
1240 
1241     @Test
1242     public void filenameFilename()
1243         throws Exception
1244     {
1245         assertThat( FileUtils.filename( "foo.bar.txt" ), is( "foo.bar.txt" ) );
1246     }
1247 
1248     @Test
1249     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1250     public void filenameWindowsRootPathOnUnix()
1251         throws Exception
1252     {
1253         assumeThat( File.separatorChar, is( '/' ) );
1254         assertThat( FileUtils.filename( "C:\\foo.bar.txt" ), is( "C:\\foo.bar.txt" ) );
1255     }
1256 
1257     @Test
1258     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1259     public void filenameWindowsNonRootPathOnUnix()
1260         throws Exception
1261     {
1262         assumeThat( File.separatorChar, is( '/' ) );
1263         assertThat( FileUtils.filename( "C:\\test\\foo.bar.txt" ), is( "C:\\test\\foo.bar.txt" ) );
1264     }
1265 
1266     @Test
1267     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1268     public void filenameUnixRootPathOnWindows()
1269         throws Exception
1270     {
1271         assumeThat( File.separatorChar, is( '\\' ) );
1272         assertThat( FileUtils.filename( "/foo.bar.txt" ), is( "/foo.bar.txt" ) );
1273     }
1274 
1275     @Test
1276     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1277     public void filenameUnixNonRootPathOnWindows()
1278         throws Exception
1279     {
1280         assumeThat( File.separatorChar, is( '\\' ) );
1281         assertThat( FileUtils.filename( "/test/foo.bar.txt" ), is( "/test/foo.bar.txt" ) );
1282     }
1283 
1284     @Test
1285     public void filenameWindowsRootPathOnWindows()
1286         throws Exception
1287     {
1288         assumeThat( File.separatorChar, is( '\\' ) );
1289         assertThat( FileUtils.filename( "C:\\foo.bar.txt" ), is( "foo.bar.txt" ) );
1290     }
1291 
1292     @Test
1293     public void filenameWindowsNonRootPathOnWindows()
1294         throws Exception
1295     {
1296         assumeThat( File.separatorChar, is( '\\' ) );
1297         assertThat( FileUtils.filename( "C:\\test\\foo.bar.txt" ), is( "foo.bar.txt" ) );
1298     }
1299 
1300     @Test
1301     public void filenameUnixRootPathOnUnix()
1302         throws Exception
1303     {
1304         assumeThat( File.separatorChar, is( '/' ) );
1305         assertThat( FileUtils.filename( "/foo.bar.txt" ), is( "foo.bar.txt" ) );
1306     }
1307 
1308     @Test
1309     public void filenameUnixNonRootPathOnUnix()
1310         throws Exception
1311     {
1312         assumeThat( File.separatorChar, is( '/' ) );
1313         assertThat( FileUtils.filename( "/test/foo.bar.txt" ), is( "foo.bar.txt" ) );
1314     }
1315 
1316     //// extension(String)
1317 
1318     @SuppressWarnings("ConstantConditions")
1319     @Test( expected = NullPointerException.class )
1320     public void blowUpOnNullExtension()
1321         throws Exception
1322     {
1323         FileUtils.extension( null );
1324     }
1325 
1326     @Test
1327     public void extensionEmpty()
1328         throws Exception
1329     {
1330         assertThat( FileUtils.extension( "" ), is( "" ) );
1331     }
1332 
1333     @Test
1334     public void extensionFileName()
1335         throws Exception
1336     {
1337         assertThat( FileUtils.extension( "foo.bar.txt" ), is( "txt" ) );
1338     }
1339 
1340     @Test
1341     public void extensionFileNameNoExtension()
1342         throws Exception
1343     {
1344         assertThat( FileUtils.extension( "foo_bar_txt" ), is( "" ) );
1345     }
1346 
1347     @Test
1348     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1349     public void extensionWindowsRootPathOnUnix()
1350         throws Exception
1351     {
1352         assumeThat( File.separatorChar, is( '/' ) );
1353         assertThat( FileUtils.extension( "C:\\foo.bar.txt" ), is( "txt" ) );
1354     }
1355 
1356     @Test
1357     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1358     public void extensionWindowsNonRootPathOnUnix()
1359         throws Exception
1360     {
1361         assumeThat( File.separatorChar, is( '/' ) );
1362         assertThat( FileUtils.extension( "C:\\test\\foo.bar.txt" ), is( "txt" ) );
1363     }
1364 
1365     @Test
1366     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1367     public void extensionUnixRootPathOnWindows()
1368         throws Exception
1369     {
1370         assumeThat( File.separatorChar, is( '\\' ) );
1371         assertThat( FileUtils.extension( "/foo.bar.txt" ), is( "txt" ) );
1372     }
1373 
1374     @Test
1375     //X @ReproducesPlexusBug( "assumes that the path is a local path" )
1376     public void extensionUnixNonRootPathOnWindows()
1377         throws Exception
1378     {
1379         assumeThat( File.separatorChar, is( '\\' ) );
1380         assertThat( FileUtils.extension( "/test/foo.bar.txt" ), is( "txt" ) );
1381     }
1382 
1383     @Test
1384     public void extensionWindowsRootPathOnWindows()
1385         throws Exception
1386     {
1387         assumeThat( File.separatorChar, is( '\\' ) );
1388         assertThat( FileUtils.extension( "C:\\foo.bar.txt" ), is( "txt" ) );
1389     }
1390 
1391     @Test
1392     public void extensionWindowsNonRootPathOnWindows()
1393         throws Exception
1394     {
1395         assumeThat( File.separatorChar, is( '\\' ) );
1396         assertThat( FileUtils.extension( "C:\\test\\foo.bar.txt" ), is( "txt" ) );
1397     }
1398 
1399     @Test
1400     @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly")
1401     public void isASymbolicLink()
1402         throws IOException
1403     {
1404         // This testcase will pass when running under java7 or higher
1405         assumeThat( Os.isFamily(Os.FAMILY_WINDOWS), is(false) );
1406 
1407         File file = new File( "src/test/resources/symlinks/src/symDir" );
1408         assertTrue(FileUtils.isSymbolicLink(file  ));
1409         assertTrue(FileUtils.isSymbolicLinkLegacy(file  ));
1410     }
1411 
1412     @Test
1413     @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly")
1414     public void notASymbolicLink()
1415         throws IOException
1416     {
1417         File file = new File( "src/test/resources/symlinks/src/" );
1418         assertFalse(FileUtils.isSymbolicLink(file  ));
1419         assertFalse(FileUtils.isSymbolicLinkLegacy(file  ));
1420     }
1421 
1422     @Test
1423     public void extensionUnixRootPathOnUnix()
1424         throws Exception
1425     {
1426         assumeThat( File.separatorChar, is( '/' ) );
1427         assertThat( FileUtils.extension( "/foo.bar.txt" ), is( "txt" ) );
1428     }
1429 
1430     @Test
1431     public void extensionUnixNonRootPathOnUnix()
1432         throws Exception
1433     {
1434         assumeThat( File.separatorChar, is( '/' ) );
1435         assertThat( FileUtils.extension( "/test/foo.bar.txt" ), is( "txt" ) );
1436     }
1437 
1438     //// constants for testing
1439 
1440     private static final String[] MINIMUM_DEFAULT_EXCLUDES = {
1441         // Miscellaneous typical temporary files
1442         "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
1443 
1444         // CVS
1445         "**/CVS", "**/CVS/**", "**/.cvsignore",
1446 
1447         // Subversion
1448         "**/.svn", "**/.svn/**",
1449 
1450         // Arch
1451         "**/.arch-ids", "**/.arch-ids/**",
1452 
1453         //Bazaar
1454         "**/.bzr", "**/.bzr/**",
1455 
1456         //SurroundSCM
1457         "**/.MySCMServerInfo",
1458 
1459         // Mac
1460         "**/.DS_Store",
1461 
1462         // Serena Dimensions Version 10
1463         "**/.metadata", "**/.metadata/**",
1464 
1465         // Mercurial
1466         "**/.hg", "**/.hg/**",
1467 
1468         // git
1469         "**/.git", "**/.git/**",
1470 
1471         // BitKeeper
1472         "**/BitKeeper", "**/BitKeeper/**", "**/ChangeSet", "**/ChangeSet/**",
1473 
1474         // darcs
1475         "**/_darcs", "**/_darcs/**", "**/.darcsrepo", "**/.darcsrepo/**", "**/-darcs-backup*", "**/.darcs-temp-mail" };
1476 
1477 }