You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/06/16 01:10:30 UTC

svn commit: r1136244 - in /maven/sandbox/trunk/plexus-utils-commons-bridge: plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/FileUtils.java plexus-utils-tck/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java

Author: stephenc
Date: Wed Jun 15 23:10:30 2011
New Revision: 1136244

URL: http://svn.apache.org/viewvc?rev=1136244&view=rev
Log:
fix some of the new impl and add some more tests

Modified:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/FileUtils.java
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/FileUtils.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/FileUtils.java?rev=1136244&r1=1136243&r2=1136244&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/FileUtils.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/FileUtils.java Wed Jun 15 23:10:30 2011
@@ -121,7 +121,7 @@ public class FileUtils
     public static String dirname( String name )
     {
         name.getClass();
-        return FilenameUtils.getPathNoEndSeparator( name );
+        return FilenameUtils.getFullPathNoEndSeparator( name );
     }
 
     public static String filename( String name )
@@ -132,7 +132,8 @@ public class FileUtils
 
     public static String basename( String name )
     {
-        throw new UnsupportedOperationException( "TODO: Implement" );
+        name.getClass();
+        return FilenameUtils.getBaseName( name );
     }
 
     public static String basename( String s1, String s2 )
@@ -142,7 +143,8 @@ public class FileUtils
 
     public static String extension( String name )
     {
-        throw new UnsupportedOperationException( "TODO: Implement" );
+        name.getClass();
+        return FilenameUtils.getExtension( name );
     }
 
     public static boolean fileExists( String name )

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java?rev=1136244&r1=1136243&r2=1136244&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java Wed Jun 15 23:10:30 2011
@@ -1466,6 +1466,202 @@ public class FileUtilsTest
         assertThat( FileUtils.filename( "/test/foo.bar.txt" ), is( "foo.bar.txt" ) );
     }
 
+    //// basename(String)
+
+    @Test( expected = NullPointerException.class )
+    public void basenameNull()
+        throws Exception
+    {
+        FileUtils.basename( null );
+    }
+
+    @Test
+    public void basenameEmpty()
+        throws Exception
+    {
+        assertThat( FileUtils.basename( "" ), is( "" ) );
+    }
+
+    @Test
+    public void basenameFilename()
+        throws Exception
+    {
+        assertThat( FileUtils.basename( "foo.bar.txt" ), is( "foo.bar." ) );
+    }
+
+    @Test
+    public void basenameFilenameNoExtension()
+        throws Exception
+    {
+        assertThat( FileUtils.basename( "foo_bar_txt" ), is( "foo_bar_txt" ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void basenameWindowsRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.basename( "C:\\foo.bar.txt" ), is( "C:\\foo.bar." ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void basenameWindowsNonRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.basename( "C:\\test\\foo.bar.txt" ), is( "C:\\test\\foo.bar." ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void basenameUnixRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.basename( "/foo.bar.txt" ), is( "/foo.bar." ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void basenameUnixNonRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.basename( "/test/foo.bar.txt" ), is( "/test/foo.bar." ) );
+    }
+
+    @Test
+    public void basenameWindowsRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.basename( "C:\\foo.bar.txt" ), is( "foo.bar." ) );
+    }
+
+    @Test
+    public void basenameWindowsNonRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.basename( "C:\\test\\foo.bar.txt" ), is( "foo.bar." ) );
+    }
+
+    @Test
+    public void basenameUnixRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.basename( "/foo.bar.txt" ), is( "foo.bar." ) );
+    }
+
+    @Test
+    public void basenameUnixNonRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.basename( "/test/foo.bar.txt" ), is( "foo.bar." ) );
+    }
+
+    //// extension(String)
+
+    @Test( expected = NullPointerException.class )
+    public void extensionNull()
+        throws Exception
+    {
+        FileUtils.extension( null );
+    }
+
+    @Test
+    public void extensionEmpty()
+        throws Exception
+    {
+        assertThat( FileUtils.extension( "" ), is( "" ) );
+    }
+
+    @Test
+    public void extensionFileName()
+        throws Exception
+    {
+        assertThat( FileUtils.extension( "foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    public void extensionFileNameNoExtension()
+        throws Exception
+    {
+        assertThat( FileUtils.extension( "foo_bar_txt" ), is( "" ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void extensionWindowsRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.extension( "C:\\foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void extensionWindowsNonRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.extension( "C:\\test\\foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void extensionUnixRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.extension( "/foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    @ReproducesPlexusBug( "assumes that the path is a local path" )
+    public void extensionUnixNonRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.extension( "/test/foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    public void extensionWindowsRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.extension( "C:\\foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    public void extensionWindowsNonRootPathOnWindows()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '\\' ) );
+        assertThat( FileUtils.extension( "C:\\test\\foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    public void extensionUnixRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.extension( "/foo.bar.txt" ), is( "txt" ) );
+    }
+
+    @Test
+    public void extensionUnixNonRootPathOnUnix()
+        throws Exception
+    {
+        assumeThat( File.separatorChar, is( '/' ) );
+        assertThat( FileUtils.extension( "/test/foo.bar.txt" ), is( "txt" ) );
+    }
+
     //// constants for testing
 
     private static final String[] MINIMUM_DEFAULT_EXCLUDES = {