Author: struberg
Date: Wed Aug 17 16:49:28 2011
New Revision: 1158823

URL: http://svn.apache.org/viewvc?rev=1158823&view=rev
Log:
MSANDBOX-51 add TCK for StringUtils

Added:
    
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
      - copied, changed from r1158747, 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PathToolTest.java

Copied: 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
 (from r1158747, 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PathToolTest.java)
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java?p2=maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java&p1=maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PathToolTest.java&r1=1158747&r2=1158823&rev=1158823&view=diff
==============================================================================
--- 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PathToolTest.java
 (original)
+++ 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
 Wed Aug 17 16:49:28 2011
@@ -21,24 +21,23 @@ package org.codehaus.plexus.util;
 
 import org.apache.maven.tck.FixPlexusBugs;
 import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.Assert;
 import org.junit.rules.TemporaryFolder;
 
 
-import java.io.File;
-
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 
 
 /**
- * Test the {@link PathTool} class.
+ * Test the {@link org.codehaus.plexus.util.StringUtils} class.
  *
  * We don't need to test this
  * @author <a href="mailto:strub...@yahoo.de";>Mark Struberg</a>
  */
-public class PathToolTest extends Assert
+public class StringUtilsTest extends Assert
 {
 
     @Rule
@@ -47,149 +46,128 @@ public class PathToolTest extends Assert
     @Rule
     public TemporaryFolder tempFolder = new TemporaryFolder();
 
-    @Test
-    public void testCalculateLink()
-    {
-        assertThat( PathTool.calculateLink( "/index.html", "../.." )
-                  , is( "../../index.html" ) );
-
-        assertThat( PathTool.calculateLink( 
"http://plexus.codehaus.org/plexus-utils/index.html";, "../.." )
-                  , is( "http://plexus.codehaus.org/plexus-utils/index.html"; ) 
);
-
-        assertThat( PathTool.calculateLink( "/usr/local/java/bin/java.sh", 
"../.." )
-                  , is( "../../usr/local/java/bin/java.sh" ) );
 
-        assertThat( PathTool.calculateLink( "../index.html", 
"/usr/local/java/bin" )
-                  , is( "/usr/local/java/bin/../index.html" ) );
+    @Test(expected = NullPointerException.class)
+    public void testAbbreviate_NPE()
+    {
+        assertThat( StringUtils.abbreviate( null, 10 )
+                , CoreMatchers.<Object>nullValue() );
+    }
 
-        assertThat( PathTool.calculateLink( "../index.html", 
"http://plexus.codehaus.org/plexus-utils"; )
-                  , is( 
"http://plexus.codehaus.org/plexus-utils/../index.html"; ) );
+    @Test(expected = IllegalArgumentException.class)
+    public void testAbbreviate_MinLength()
+    {
+        assertThat( StringUtils.abbreviate( "This is a longtext", 3 )
+                  , is( "T" ) );
     }
 
     @Test
-    public void testGetDirectoryComponent()
+    public void testAbbreviate()
     {
-        assertThat( PathTool.getDirectoryComponent( null )
-                  , is( "" ) );
+        assertThat( StringUtils.abbreviate( "This is a longtext", 10 )
+                  , is( "This is..." ) );
 
-        assertThat( PathTool.getDirectoryComponent( "/usr/local/java/bin" )
-                  , is( "/usr/local/java" ) );
+        assertThat( StringUtils.abbreviate( "This is a longtext", 50 )
+                  , is( "This is a longtext" ) );
+    }
 
-        assertThat( PathTool.getDirectoryComponent( "/usr/local/java/bin/" )
-                  , is( "/usr/local/java/bin" ) );
+    @Test(expected = NullPointerException.class)
+    public void testAbbreviate_Offset_NPE()
+    {
+        assertThat( StringUtils.abbreviate( null, 10, 20 )
+                , CoreMatchers.<Object>nullValue() );
+    }
 
-        assertThat( PathTool.getDirectoryComponent( 
"/usr/local/java/bin/java.sh" )
-                  , is( "/usr/local/java/bin" ) );
+    @Test(expected = IllegalArgumentException.class)
+    public void testAbbreviate_Offset_MinLength()
+    {
+        assertThat( StringUtils.abbreviate( "This is a longtext", 10, 3 )
+                  , is( "T" ) );
     }
 
     @Test
-    public void testGetRelativeFilePath()
+    public void testAbbreviate_Offset()
     {
-        assertThat( PathTool.getRelativeFilePath( null, null )
-                  , is( "" ) );
-
-        assertThat( PathTool.getRelativeFilePath( null, "/usr/local/java/bin" )
-                  , is( "" ) );
-
-        assertThat( PathTool.getRelativeFilePath( "/usr/local", null )
-                  , is( "" ) );
-
-        assertThat( PathTool.getRelativeFilePath( "/usr/local", 
"/usr/local/java/bin" )
-                  , is( "java/bin" ) );
-
-        assertThat( PathTool.getRelativeFilePath( "/usr/local", 
"/usr/local/java/bin/" )
-                  , is( "java/bin/" ) );
+        assertThat( StringUtils.abbreviate( "This is a longtext", 5, 10 )
+                  , is( "...is a..." ) );
 
-        assertThat( PathTool.getRelativeFilePath( "/usr/local/java/bin", 
"/usr/local/" )
-                  , is( "../../" ) );
+        assertThat( StringUtils.abbreviate( "This is a longtext", 10, 20 )
+                  , is( "This is a longtext" ) );
 
-        assertThat( PathTool.getRelativeFilePath( "/usr/local/", 
"/usr/local/java/bin/java.sh" )
-                  , is( "java/bin/java.sh" ) );
-
-        assertThat( PathTool.getRelativeFilePath( 
"/usr/local/java/bin/java.sh", "/usr/local/" )
-                  , is( "../../../" ) );
-
-        assertThat( PathTool.getRelativeFilePath( "/usr/local/", "/bin" )
-                  , is( "../../bin" ) );
+        assertThat( StringUtils.abbreviate( "This is a longtext", 50, 20 )
+                  , is( "This is a longtext" ) );
+    }
 
-        assertThat( PathTool.getRelativeFilePath( "/bin", "/usr/local/" )
-                  , is( "../usr/local/" ) );
+    @Test( expected = NullPointerException.class )
+    public void testAddAndDeHump_NPE()
+    {
+        StringUtils.addAndDeHump( null );
     }
 
     @Test
-    public void testGetRelativePath_2parm()
+    public void testAddAndDeHump()
     {
-        assertThat( PathTool.getRelativePath( null, null )
-                  , is( "" ) );
-
-        assertThat( PathTool.getRelativePath( null, "/usr/local/java/bin" )
-                  , is( "" ) );
+        assertThat( StringUtils.addAndDeHump( "lalala" )
+                  , is( "lalala" ) );
 
-        assertThat( PathTool.getRelativePath( "/usr/local/", null )
-                  , is( "" ) );
+        assertThat( StringUtils.addAndDeHump( "LaLaLa" )
+                  , is( "la-la-la" ) );
 
-        assertThat( PathTool.getRelativePath( "/usr/local/", 
"/usr/local/java/bin" )
-                  , is( ".." ) );
+        assertThat( StringUtils.addAndDeHump( "ALLUPPER" )
+                  , is( "a-l-l-u-p-p-e-r" ) );
 
-        assertThat( PathTool.getRelativePath( "/usr/local/", 
"/usr/local/java/bin/java.sh" )
-                  , is( "../.." ) );
-
-        assertThat( PathTool.getRelativePath( "/usr/local/java/bin/java.sh", 
"/usr/local/" )
-                  , is( "" ) );
     }
 
     @Test
-    public void testGetRelativePath_1parm()
+    public void testCapitalise()
     {
-        assertThat( PathTool.getRelativePath( null )
-                  , is( "" ) );
-
-        File baseFolder = tempFolder.newFolder( "pathtooltest" );
-
-        String folderName = "anotherFolders";
-        File newDir = new File( baseFolder, folderName );
-        newDir.mkdirs();
+        assertThat( StringUtils.capitalise( null )
+                , nullValue() );
 
-
-        assertThat( PathTool.getRelativePath( folderName )
-                  , is( "." ) );
+        assertThat( StringUtils.capitalise( "startBig" )
+                , is( "StartBig" ) );
     }
 
     @Test
-    public void testGetRelativeWebPath()
+    public void testCapitaliseAllWords()
     {
-        assertThat( PathTool.getRelativeWebPath( null, null )
-                  , is( "" ) );
+        assertThat( StringUtils.capitaliseAllWords( null )
+                , nullValue() );
 
-        assertThat( PathTool.getRelativeWebPath( null, 
"http://plexus.codehaus.org/"; )
-                  , is( "" ) );
+        assertThat( StringUtils.capitaliseAllWords( "start all big" )
+                , is( "Start All Big" ) );
+    }
 
-        assertThat( PathTool.getRelativeWebPath( 
"http://plexus.codehaus.org/";, null )
-                  , is( "" ) );
+    @Test( expected = NullPointerException.class )
+    public void testCapitalizeFirstLetter_NPE()
+    {
+        assertThat( StringUtils.capitalizeFirstLetter( null )
+                , nullValue() );
+    }
 
-        assertThat( PathTool.getRelativeWebPath( "http://plexus.codehaus.org/";
-                                               , 
"http://plexus.codehaus.org/plexus-utils/index.html"; )
-                  , is( "plexus-utils/index.html" ) );
+    @Test
+    public void testCapitalizeFirstLetter()
+    {
+        assertThat( StringUtils.capitalizeFirstLetter( "start all big" )
+                , is( "Start all big" ) );
+    }
 
-        assertThat( PathTool.getRelativeWebPath( 
"http://plexus.codehaus.org/plexus-utils/index.html";
-                                               , "http://plexus.codehaus.org/"; 
)
-                  , is( "../../" ) );
+    @Test( expected = NullPointerException.class )
+    public void testCenter_NPE()
+    {
+        StringUtils.center( null, 20 );
     }
 
     @Test
-    public void testUppercaseDrive()
+    public void testCenter()
     {
-        assertThat( PathTool.uppercaseDrive( null )
-                , CoreMatchers.<Object>nullValue() );
+        assertThat( StringUtils.center( "centerMe", 20 )
+                , is( "      centerMe      " ) );
 
-        assertThat( PathTool.uppercaseDrive( "d:" )
-                , is( "D:" ) );
+        assertThat( StringUtils.center( "centerMe", 4 )
+                , is( "centerMe" ) );
 
-        assertThat( PathTool.uppercaseDrive( "D:" )
-                , is( "D:" ) );
-
-        assertThat( PathTool.uppercaseDrive( "/notadrive" )
-                , is( "/notadrive" ) );
+        assertThat( StringUtils.center( "        centerMe", 20 )
+                , is( "          centerMe  " ) );
     }
-
 }


Reply via email to