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/08/27 12:57:10 UTC

svn commit: r1162323 - /maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java

Author: struberg
Date: Sat Aug 27 10:57:09 2011
New Revision: 1162323

URL: http://svn.apache.org/viewvc?rev=1162323&view=rev
Log:
MSANDBOX-51 StringUtilsTest almost finished...

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

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.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?rev=1162323&r1=1162322&r2=1162323&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java Sat Aug 27 10:57:09 2011
@@ -1654,52 +1654,195 @@ public class StringUtilsTest extends Ass
                   , is( "bums dings" ) );
     }
 
+    @Test( expected = IllegalArgumentException.class )
+    public void testRight_IAE1()
+    {
+        StringUtils.right( null, -1 );
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void testRight_IAE2()
+    {
+        StringUtils.right( "dings", -1 );
+    }
+
     @Test
     public void testRight()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.right( null, 0 )
+                  , nullValue() );
+
+        assertThat( StringUtils.right( "dings", 0 )
+                  , is( "" ) );
+
+        assertThat( StringUtils.right( "dings", 3 )
+                  , is( "ngs" ) );
+
+        assertThat( StringUtils.right( "dings ", 3 )
+                  , is( "gs " ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testRightPad1_NPE()
+    {
+        StringUtils.rightPad( null, 0 );
     }
 
     @Test
     public void testRightPad1()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.rightPad( "dings", 0 )
+                  , is( "dings" ) );
+
+        assertThat( StringUtils.rightPad( "dings", 3 )
+                  , is( "dings" ) );
+
+        assertThat( StringUtils.rightPad( "dings", 10 )
+                  , is( "dings     " ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testRightPad2_NPE1()
+    {
+        StringUtils.rightPad( null, 0, null );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testRightPad2_NPE2()
+    {
+        StringUtils.rightPad( "dings", 0, null );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testRightPad2_NPE23()
+    {
+        StringUtils.rightPad( null, 0, "+" );
     }
 
     @Test
     public void testRightPad2()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.rightPad( "dings", 0, "+" )
+                  , is( "dings" ) );
+
+        assertThat( StringUtils.rightPad( "dings", 3, "+" )
+                  , is( "dings" ) );
+
+        assertThat( StringUtils.rightPad( "dings", 10, "+" )
+                  , is( "dings+++++" ) );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void testSplit1_NPE()
+    {
+        StringUtils.split( null );
     }
 
     @Test
     public void testSplit1()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.split( "dings" )
+                  , is( new String[]{"dings"} )  );
+
+        assertThat( StringUtils.split( "dings bums" )
+                  , is( new String[]{"dings", "bums"} )  );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testSplit2_NPE1()
+    {
+        StringUtils.split( null, null );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testSplit2_NPE2()
+    {
+        StringUtils.split( null, " " );
     }
 
     @Test
     public void testSplit2()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.split( "dings", null )
+                  , is( new String[]{"dings"} )  );
+
+        assertThat( StringUtils.split( "dings bums", null )
+                  , is( new String[]{"dings", "bums"} )  );
+
+        assertThat( StringUtils.split( "dings", "+" )
+                  , is( new String[]{"dings"} )  );
+
+        assertThat( StringUtils.split( "dings+bums", "+" )
+                  , is( new String[]{"dings", "bums"} )  );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testSplit3_NPE1()
+    {
+        StringUtils.split( null, null, 1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testSplit3_NPE2()
+    {
+        StringUtils.split( null, " ", 1 );
     }
 
     @Test
     public void testSplit3()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.split( "dings", null, 3 )
+                  , is( new String[]{"dings"} )  );
+
+        assertThat( StringUtils.split( "dings bums", null, 3 )
+                  , is( new String[]{"dings", "bums"} )  );
+
+        assertThat( StringUtils.split( "dings", "+", 3 )
+                  , is( new String[]{"dings"} )  );
+
+        assertThat( StringUtils.split( "dings+bums", "+", 3 )
+                  , is( new String[]{"dings", "bums"} )  );
+
+        assertThat( StringUtils.split( "dings+bums", "+", 1 )
+                  , is( new String[]{"dings+bums"} )  );
+
+        assertThat( StringUtils.split( "dings+bums", "+", 0 )
+                  , is( new String[]{"dings", "bums"} )  );
+
+        assertThat( StringUtils.split( "dings+bums", "+", -5 )
+                  , is( new String[]{"dings", "bums"} )  );
+
     }
 
+
     @Test
     public void testStrip1()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.strip( null )
+                  , nullValue() );
+
+        assertThat( StringUtils.strip( "dings" )
+                  , is( "dings" ) );
+
+        assertThat( StringUtils.strip( "  dings \t " )
+                  , is( "dings" ) );
     }
 
     @Test
     public void testStrip2()
     {
-        System.out.println( "TODO IMPLEMENT TEST!" );
+        assertThat( StringUtils.strip( null, " " )
+                  , nullValue() );
+
+        assertThat( StringUtils.strip( null, null )
+                  , nullValue() );
+
+        assertThat( StringUtils.strip( "dings", " " )
+                  , is( "dings" ) );
+
+        assertThat( StringUtils.strip( "  dings \t ", " " )
+                  , is( "dings \t" ) );
     }
 
     @Test