Author: struberg Date: Sat Aug 20 10:26:15 2011 New Revision: 1159863 URL: http://svn.apache.org/viewvc?rev=1159863&view=rev Log: MSANDBOX-51 StringUtilsTest continued
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=1159863&r1=1159862&r2=1159863&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 20 10:26:15 2011 @@ -26,7 +26,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import static org.hamcrest.CoreMatchers.is; @@ -1027,28 +1029,86 @@ public class StringUtilsTest extends Ass , is( true ) ); } + @Test( expected = NullPointerException.class ) + public void testJoin_Array_NPE() + { + StringUtils.join( ( Object[] ) null, null ); + } + @Test - public void testJoin1() + public void testJoin_Array() { - System.out.println( "TODO IMPLEMENT TEST!" ); + assertThat( StringUtils.join( new Object[0], null ) + , is( "" ) ); + + assertThat( StringUtils.join( new Object[]{ "a", "b", "c"}, null ) + , is( "abc" ) ); + + assertThat( StringUtils.join( new Object[]{ "a", "b", "c"}, "__" ) + , is( "a__b__c" ) ); + } + + @Test( expected = NullPointerException.class ) + public void testJoin_Iterator_NPE() + { + StringUtils.join( (Iterator) null, null ); } @Test - public void testJoin2() + public void testJoin_Iterator() { - System.out.println( "TODO IMPLEMENT TEST!" ); + ArrayList list = new ArrayList(); + + assertThat( StringUtils.join( list.iterator(), null ) + , is( "" ) ); + + list.add( "a" ); + list.add( "b" ); + list.add( "c" ); + + assertThat( StringUtils.join( list.iterator(), null ) + , is( "abc" ) ); + + assertThat( StringUtils.join( list.iterator(), "__" ) + , is( "a__b__c" ) ); } @Test public void testLastIndexOfAny() { - System.out.println( "TODO IMPLEMENT TEST!" ); + assertThat( StringUtils.lastIndexOfAny( null, null ) + , is( -1 ) ); + + assertThat( StringUtils.lastIndexOfAny( "dings", null ) + , is( -1 ) ); + + assertThat( StringUtils.lastIndexOfAny( "dings bums boms", new String[] {"ms", " b"} ) + , is( 13 ) ); + + assertThat( StringUtils.lastIndexOfAny( "dings bums boms", new String[] {"nix", "da"} ) + , is( -1 ) ); + } + + @Test( expected = IllegalArgumentException.class ) + public void testLeft_IAE() + { + StringUtils.left( null, -1 ); } @Test public void testLeft() { - System.out.println( "TODO IMPLEMENT TEST!" ); + assertThat( StringUtils.left( null, 4 ) + , nullValue() ); + + assertThat( StringUtils.left( "dingsbums", 4 ) + , is( "ding" ) ); + + assertThat( StringUtils.left( "dingsbums", 40 ) + , is( "dingsbums" ) ); + + assertThat( StringUtils.left( "dingsbums", 0 ) + , is( "" ) ); } @Test