View Javadoc

1   package org.apache.maven.shared.utils;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.HashMap;
24  import java.util.Iterator;
25  import java.util.Map;
26  
27  import org.junit.Assert;
28  import org.junit.Rule;
29  import org.junit.Test;
30  import org.junit.rules.TemporaryFolder;
31  
32  import static org.hamcrest.CoreMatchers.is;
33  import static org.hamcrest.CoreMatchers.nullValue;
34  
35  /**
36   * Test the {@link StringUtils} class.
37   *
38   * We don't need to test this
39   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
40   */
41  public class StringUtilsTest
42      extends Assert
43  {
44  
45      @Rule
46      public TemporaryFolder tempFolder = new TemporaryFolder();
47  
48  
49      @Test( expected = NullPointerException.class )
50      public void testAbbreviate_NPE()
51      {
52          assertThat( StringUtils.abbreviate( null, 10 )
53                  , nullValue() );
54      }
55  
56      @Test( expected = IllegalArgumentException.class )
57      public void testAbbreviate_MinLength()
58      {
59          assertThat( StringUtils.abbreviate( "This is a longtext", 3 )
60                    , is( "T" ) );
61      }
62  
63      @Test
64      public void testAbbreviate()
65      {
66          assertThat( StringUtils.abbreviate( "This is a longtext", 10 )
67                    , is( "This is..." ) );
68  
69          assertThat( StringUtils.abbreviate( "This is a longtext", 50 )
70                    , is( "This is a longtext" ) );
71      }
72  
73      @Test( expected = NullPointerException.class )
74      public void testAbbreviate_Offset_NPE()
75      {
76          assertThat( StringUtils.abbreviate( null, 10, 20 )
77                  , nullValue() );
78      }
79  
80      @Test( expected = IllegalArgumentException.class )
81      public void testAbbreviate_Offset_MinLength()
82      {
83          assertThat( StringUtils.abbreviate( "This is a longtext", 10, 3 )
84                    , is( "T" ) );
85      }
86  
87      @Test
88      public void testAbbreviate_Offset()
89      {
90          assertThat( StringUtils.abbreviate( "This is a longtext", 5, 10 )
91                    , is( "...is a..." ) );
92  
93          assertThat( StringUtils.abbreviate( "This is a longtext", 10, 20 )
94                    , is( "This is a longtext" ) );
95  
96          assertThat( StringUtils.abbreviate( "This is a longtext", 50, 20 )
97                    , is( "This is a longtext" ) );
98      }
99  
100     @Test( expected = NullPointerException.class )
101     public void testAddAndDeHump_NPE()
102     {
103         StringUtils.addAndDeHump( null );
104     }
105 
106     @Test
107     public void testAddAndDeHump()
108     {
109         assertThat( StringUtils.addAndDeHump( "lalala" )
110                   , is( "lalala" ) );
111 
112         assertThat( StringUtils.addAndDeHump( "LaLaLa" )
113                   , is( "la-la-la" ) );
114 
115         assertThat( StringUtils.addAndDeHump( "ALLUPPER" )
116                   , is( "a-l-l-u-p-p-e-r" ) );
117 
118     }
119 
120     @Test
121     public void testCapitalise()
122     {
123         assertThat( StringUtils.capitalise( null )
124                 , nullValue() );
125 
126         assertThat( StringUtils.capitalise( "startBig" )
127                 , is( "StartBig" ) );
128     }
129 
130     @Test
131     public void testCapitaliseAllWords()
132     {
133         assertThat( StringUtils.capitaliseAllWords( null )
134                 , nullValue() );
135 
136         assertThat( StringUtils.capitaliseAllWords( "start all big" )
137                 , is( "Start All Big" ) );
138     }
139 
140     @Test( expected = NullPointerException.class )
141     public void testCapitalizeFirstLetter_NPE()
142     {
143         assertThat( StringUtils.capitalizeFirstLetter( null )
144                 , nullValue() );
145     }
146 
147     @Test
148     public void testCapitalizeFirstLetter()
149     {
150         assertThat( StringUtils.capitalizeFirstLetter( "Dings" )
151                 , is( "Dings" ) );
152 
153         assertThat( StringUtils.capitalizeFirstLetter( "  dings" )
154                 , is( "  dings" ) );
155 
156         assertThat( StringUtils.capitalizeFirstLetter( "start all big" )
157                 , is( "Start all big" ) );
158     }
159 
160     @Test( expected = NullPointerException.class )
161     public void testCenter_NPE()
162     {
163         StringUtils.center( null, 20 );
164     }
165 
166     @Test
167     public void testCenter()
168     {
169         assertThat( StringUtils.center( "centerMe", 20 )
170                 , is( "      centerMe      " ) );
171 
172         assertThat( StringUtils.center( "centerMe", 4 )
173                 , is( "centerMe" ) );
174 
175         assertThat( StringUtils.center( "        centerMe", 20 )
176                 , is( "          centerMe  " ) );
177     }
178 
179     @Test( expected = NullPointerException.class )
180     public void testCenter_Delim_NPE()
181     {
182         StringUtils.center( null, 20, "*" );
183     }
184 
185     @Test
186     public void testCenter_Delim()
187     {
188         assertThat( StringUtils.center( "centerMe", 20, "*" )
189                 , is( "******centerMe******" ) );
190 
191         assertThat( StringUtils.center( "centerMe", 4, "*" )
192                 , is( "centerMe" ) );
193 
194         assertThat( StringUtils.center( "        centerMe", 20, "*" )
195                 , is( "**        centerMe**" ) );
196     }
197 
198     @Test( expected = NullPointerException.class )
199     public void testChomp_NPE()
200     {
201         StringUtils.chomp( null );
202     }
203 
204     @Test
205     public void testChomp()
206     {
207         assertThat( StringUtils.chomp( "dings" )
208                 , is( "dings" ) );
209 
210         assertThat( StringUtils.chomp( "dings\n" )
211                 , is( "dings" ) );
212 
213         assertThat( StringUtils.chomp( "dings\nbums" )
214                 , is( "dings" ) );
215 
216         assertThat( StringUtils.chomp( "dings\nbums\ndongs" )
217                 , is( "dings\nbums" ) );
218     }
219 
220     @Test( expected = NullPointerException.class )
221     public void testChomp_Delim_NPE()
222     {
223         StringUtils.chomp( null, "+" );
224     }
225 
226     @Test
227     public void testChomp_Delim()
228     {
229         assertThat( StringUtils.chomp( "dings", "+" )
230                 , is( "dings" ) );
231 
232         assertThat( StringUtils.chomp( "dings+", "+" )
233                 , is( "dings" ) );
234 
235         assertThat( StringUtils.chomp( "dings+bums", "+" )
236                 , is( "dings" ) );
237 
238         assertThat( StringUtils.chomp( "dings+bums+dongs", "+" )
239                 , is( "dings+bums" ) );
240     }
241 
242 
243     @Test( expected = NullPointerException.class )
244     public void testChompLast_NPE()
245     {
246         StringUtils.chompLast( null );
247     }
248 
249     @Test
250     public void testChompLast()
251     {
252         assertThat( StringUtils.chompLast( "dings" )
253                 , is( "dings" ) );
254 
255         assertThat( StringUtils.chompLast( "\n" )
256                 , is( "" ) );
257 
258         assertThat( StringUtils.chompLast( "dings\n" )
259                 , is( "dings" ) );
260 
261         assertThat( StringUtils.chompLast( "dings\nbums" )
262                 , is( "dings\nbums" ) );
263 
264         assertThat( StringUtils.chompLast( "dings\nbums\ndongs\n" )
265                 , is( "dings\nbums\ndongs" ) );
266     }
267 
268     @Test( expected = NullPointerException.class )
269     public void testChompLast_Delim_NPE()
270     {
271         StringUtils.chompLast( null, "+" );
272     }
273 
274     @Test
275     public void testChompLast_Delim()
276     {
277         assertThat( StringUtils.chompLast( "dings", "+" )
278                 , is( "dings" ) );
279 
280         assertThat( StringUtils.chompLast( "+", "+" )
281                 , is( "" ) );
282 
283         assertThat( StringUtils.chompLast( "dings+", "+" )
284                 , is( "dings" ) );
285 
286         assertThat( StringUtils.chompLast( "dings+bums", "+" )
287                 , is( "dings+bums" ) );
288 
289         assertThat( StringUtils.chompLast( "dings+bums+dongs+", "+" )
290                 , is( "dings+bums+dongs" ) );
291     }
292 
293     @Test( expected = NullPointerException.class )
294     public void testChop_NPE()
295     {
296         StringUtils.chop( null );
297     }
298 
299     @Test
300     public void testChop()
301     {
302         assertThat( StringUtils.chop( "dings" )
303                 , is( "ding" ) );
304 
305         assertThat( StringUtils.chop( "x" )
306                 , is( "" ) );
307 
308         assertThat( StringUtils.chop( "dings\n" )
309                 , is( "dings" ) );
310 
311         assertThat( StringUtils.chop( "dings\r\n" )
312                 , is( "dings" ) );
313 
314         assertThat( StringUtils.chop( "dings\n\r" )
315                 , is( "dings\n" ) );
316     }
317 
318     @Test( expected = NullPointerException.class )
319     public void testChopNewline_NPE()
320     {
321         StringUtils.chopNewline( null );
322     }
323 
324     @Test
325     public void testChopNewline()
326     {
327         assertThat( StringUtils.chopNewline( "dings" )
328                 , is( "dings" ) );
329 
330         assertThat( StringUtils.chopNewline( "x" )
331                 , is( "x" ) );
332 
333 
334         assertThat( StringUtils.chopNewline( "dings\n" )
335                 , is( "dings" ) );
336 
337         assertThat( StringUtils.chopNewline( "dings\r\n" )
338                 , is( "dings" ) );
339 
340         assertThat( StringUtils.chopNewline( "dings\n\r" )
341                 , is( "dings\n\r" ) );
342     }
343 
344 
345     @Test
346     public void testClean()
347     {
348         assertThat( StringUtils.clean( null )
349                   , is( "" ) );
350 
351         assertThat( StringUtils.clean( "   " )
352                   , is( "" ) );
353 
354         assertThat( StringUtils.clean( "  c " )
355                   , is( "c" ) );
356 
357         assertThat( StringUtils.clean( "  dings \n  " )
358                   , is( "dings" ) );
359     }
360 
361 
362     @Test( expected = NullPointerException.class )
363     public void testConcatenate_NPE()
364     {
365         StringUtils.concatenate( null );
366     }
367 
368     @Test
369     public void testConcatenate()
370     {
371         assertThat( StringUtils.concatenate( new String[0] )
372                   , is( "" ) );
373 
374         assertThat( StringUtils.concatenate( new String[]{ "x" } )
375                   , is( "x" ) );
376 
377         assertThat( StringUtils.concatenate( new String[]{ "x", "y", "z" } )
378                   , is( "xyz" ) );
379     }
380 
381     @Test
382     public void testContains_String()
383     {
384         assertThat( StringUtils.contains( null, null )
385                 , is( false ) );
386 
387         assertThat( StringUtils.contains( null, "string" )
388                 , is( false ) );
389 
390         assertThat( StringUtils.contains( "string", null )
391                 , is( false ) );
392 
393         assertThat( StringUtils.contains( "string", "" )
394                 , is( true ) );
395 
396         assertThat( StringUtils.contains( "string", "in" )
397                 , is( true ) );
398 
399         assertThat( StringUtils.contains( "string", "IN" )
400                 , is( false ) );
401     }
402 
403     @Test
404     public void testContains_Char()
405     {
406         assertThat( StringUtils.contains( null, 'c' )
407                 , is( false ) );
408 
409         assertThat( StringUtils.contains( "string", "c" )
410                 , is( false ) );
411 
412         assertThat( StringUtils.contains( "string", "" )
413                 , is( true ) );
414 
415         assertThat( StringUtils.contains( "string", "r" )
416                 , is( true ) );
417 
418         assertThat( StringUtils.contains( "string", "R" )
419                 , is( false ) );
420 
421     }
422 
423     @Test( expected = NullPointerException.class )
424     public void testCountMatches_NPE()
425     {
426          StringUtils.countMatches( null, null );
427     }
428 
429     @Test( expected = NullPointerException.class )
430     public void testCountMatches_NPE2()
431     {
432          StringUtils.countMatches( "this is it", null );
433     }
434 
435     @Test
436     public void testCountMatches()
437     {
438         assertThat( StringUtils.countMatches( null, "is" )
439                   , is( 0 ) );
440 
441         assertThat( StringUtils.countMatches( "this is it", "is" )
442                   , is( 2 ) );
443 
444         assertThat( StringUtils.countMatches( "this is it", "notincluded" )
445                   , is( 0 ) );
446     }
447 
448     @Test
449     public void testDefaultString()
450     {
451          assertThat( StringUtils.defaultString( null )
452                    , is( "" ) );
453 
454         assertThat( StringUtils.defaultString( "dings" )
455                   , is( "dings" ) );
456     }
457 
458     @Test
459     public void testDefaultString_defaultValue()
460     {
461          assertThat( StringUtils.defaultString( null, "defaultValue" )
462                    , is( "defaultValue" ) );
463 
464         assertThat( StringUtils.defaultString( "dings", "defaultValue" )
465                   , is( "dings" ) );
466     }
467 
468     @Test( expected = NullPointerException.class )
469     public void testDeleteWhitespace_NPE()
470     {
471         StringUtils.deleteWhitespace( null );
472     }
473 
474     @Test
475     public void testDeleteWhitespace()
476     {
477         assertThat( StringUtils.deleteWhitespace( " \t  \n" )
478                   , is( "" ) );
479 
480         assertThat( StringUtils.deleteWhitespace( " \t  \b \n" )
481                   , is( "\b" ) );
482 
483         assertThat( StringUtils.deleteWhitespace( "dings" )
484                 , is( "dings" ) );
485 
486         assertThat( StringUtils.deleteWhitespace( "\n  dings \t " )
487                   , is( "dings" ) );
488     }
489 
490     @Test( expected = NullPointerException.class )
491     public void testDifference_NPE()
492     {
493         StringUtils.difference( null, null );
494     }
495 
496     @Test( expected = NullPointerException.class )
497     public void testDifference_NPE2()
498     {
499         StringUtils.difference( null, "another" );
500     }
501 
502     @Test( expected = NullPointerException.class )
503     public void testDifference_NPE3()
504     {
505         StringUtils.difference( "this", null );
506     }
507 
508     @Test
509     public void testDifference()
510     {
511         assertThat( StringUtils.difference( "this", "another" )
512                 , is( "another" ) );
513 
514         assertThat( StringUtils.difference( "I am human", "I am a robot" )
515                   , is( "a robot" ) );
516 
517         assertThat( StringUtils.difference( "I am human", "I AM a robot" )
518                   , is( "AM a robot" ) );
519     }
520 
521     @Test( expected = NullPointerException.class )
522     public void testDifferenceAt_NPE()
523     {
524         StringUtils.differenceAt( null, null );
525     }
526 
527     @Test( expected = NullPointerException.class )
528     public void testDifferenceAt_NPE2()
529     {
530         StringUtils.differenceAt( "test", null );
531     }
532 
533     @Test( expected = NullPointerException.class )
534     public void testDifferenceAt_NPE3()
535     {
536         StringUtils.differenceAt( null, "test" );
537     }
538 
539     @Test
540     public void testDifferenceAt()
541     {
542         assertThat( StringUtils.differenceAt( "this", "another" )
543                   , is( 0 ) );
544 
545         assertThat( StringUtils.differenceAt( "I am human", "I am a robot" )
546                   , is( 5 ) );
547 
548         assertThat( StringUtils.differenceAt( "I am human", "I AM a robot" )
549                 , is( 2 ) );
550     }
551 
552     @Test
553     public void testEquals()
554     {
555         assertThat( StringUtils.equals( null, null )
556                   , is( true ) );
557 
558         assertThat( StringUtils.equals( "x", null )
559                   , is( false ) );
560 
561         assertThat( StringUtils.equals( null, "x" )
562                   , is( false ) );
563 
564         assertThat( StringUtils.equals( "X", "x" )
565                   , is( false ) );
566 
567         assertThat( StringUtils.equals( "dings", "dings" )
568                   , is( true ) );
569     }
570 
571     @Test
572     public void testEqualsIgnoreCase()
573     {
574         assertThat( StringUtils.equalsIgnoreCase( null, null )
575                   , is( true ) );
576 
577         assertThat( StringUtils.equalsIgnoreCase( "x", null )
578                   , is( false ) );
579 
580         assertThat( StringUtils.equalsIgnoreCase( null, "x" )
581                   , is( false ) );
582 
583         assertThat( StringUtils.equalsIgnoreCase( "X", "x" )
584                   , is( true ) );
585 
586         assertThat( StringUtils.equalsIgnoreCase( "dings", "dings" )
587                   , is( true ) );
588 
589         assertThat( StringUtils.equalsIgnoreCase( "dings", "diNGs" )
590                   , is( true ) );
591     }
592 
593     @Test( expected = NullPointerException.class )
594     public void testEscape_NPE()
595     {
596         StringUtils.escape( null );
597     }
598 
599     @Test
600     public void testEscape()
601     {
602         assertThat( StringUtils.escape( "dings" )
603                   , is( "dings" ) );
604 
605         assertThat( StringUtils.escape( "dings\tbums" )
606                   , is( "dings\\tbums" ) );
607 
608         assertThat( StringUtils.escape( "dings\nbums" )
609                   , is( "dings\\nbums" ) );
610     }
611 
612 
613     @Test
614     public void testEscape2()
615     {
616         assertThat( StringUtils.escape( null, null, '#' )
617                   , nullValue() );
618 
619         assertThat( StringUtils.escape( "dings", new char[]{ '\t', '\b' }, '+' )
620                   , is( "dings" ) );
621 
622         assertThat( StringUtils.escape( "dings\tbums", new char[]{ '\t', '\b' }, '+' )
623                   , is( "dings+\tbums" ) );
624 
625         assertThat( StringUtils.escape( "dings\nbums", new char[]{ '\t', '\b' }, '+' )
626                   , is( "dings\nbums" ) );
627         assertThat( StringUtils.escape( "dings\bbums", new char[]{ '\t', '\b' }, '+' )
628                   , is( "dings+\bbums" ) );
629     }
630 
631     @Test( expected = NullPointerException.class )
632     public void testGetChomp_NPE1()
633     {
634         StringUtils.getChomp( null, null );
635     }
636 
637     @Test( expected = NullPointerException.class )
638     public void testGetChomp_NPE2()
639     {
640         StringUtils.getChomp( "dings", null );
641     }
642 
643     @Test( expected = NullPointerException.class )
644     public void testGetChomp_NPE3()
645     {
646         StringUtils.getChomp( null, "dings" );
647     }
648 
649     @Test
650     public void testGetChomp()
651     {
652         assertThat( StringUtils.getChomp( "dings-bums", "-" )
653                   , is( "-bums" ) );
654 
655         assertThat( StringUtils.getChomp( "dings-", "-" )
656                   , is( "-" ) );
657 
658         assertThat( StringUtils.getChomp( "dingsbums", "-" )
659                 , is( "" ) );
660     }
661 
662     @Test( expected = NullPointerException.class )
663     public void testGetNestedString_NPE()
664     {
665         assertThat( StringUtils.getNestedString( "  +dings+ ", null )
666                 , nullValue() );
667     }
668 
669     @Test
670     public void testGetNestedString()
671     {
672         assertThat( StringUtils.getNestedString( null, null )
673                   , nullValue() );
674 
675         assertThat( StringUtils.getNestedString( "  +dings+ ", "+" )
676                   , is( "dings" ) );
677 
678         assertThat( StringUtils.getNestedString( "  +dings+ ", "not" )
679                   , nullValue() );
680     }
681 
682     @Test( expected = NullPointerException.class )
683     public void testGetNestedString2_NPE1()
684     {
685         assertThat( StringUtils.getNestedString( "  +dings+ ", null, null )
686                   , nullValue() );
687     }
688 
689     @Test( expected = NullPointerException.class )
690     public void testGetNestedString2_NPE2()
691     {
692         assertThat( StringUtils.getNestedString( "  +dings+ ", null, "neither" )
693                   , nullValue() );
694     }
695 
696     @Test
697     public void testGetNestedString2()
698     {
699         assertThat( StringUtils.getNestedString( null, null, null )
700                   , nullValue() );
701 
702         assertThat( StringUtils.getNestedString( "  +dings+ ", "not", null )
703                   , nullValue() );
704 
705         assertThat( StringUtils.getNestedString( "  +dings- ", "+", "-" )
706                   , is( "dings" ) );
707 
708         assertThat( StringUtils.getNestedString( "  +dings+ ", "not", "neither" )
709                   , nullValue() );
710     }
711 
712     @Test( expected = NullPointerException.class )
713     public void testGetPrechomp_NPE1()
714     {
715         StringUtils.getPrechomp( null, null );
716     }
717 
718     @Test( expected = NullPointerException.class )
719     public void testGetPrechomp_NPE2()
720     {
721         StringUtils.getPrechomp( null, "bums" );
722     }
723 
724     @Test
725     public void testGetPrechomp()
726     {
727         assertThat( StringUtils.getPrechomp( "dings bums dongs", "bums" )
728                   , is( "dings bums" ) );
729 
730         assertThat( StringUtils.getPrechomp( "dings bums dongs", "non" )
731                 , is( "" ) );
732     }
733 
734     @Test
735     public void testIndexOfAny()
736     {
737         assertThat( StringUtils.indexOfAny( null, null )
738                   , is( -1 ) );
739 
740         assertThat( StringUtils.indexOfAny( "dings", null )
741                   , is( -1 ) );
742 
743         assertThat( StringUtils.indexOfAny( null, new String[]{} )
744                   , is( -1 ) );
745 
746         assertThat( StringUtils.indexOfAny( "dings bums dongs", new String[]{ "knuff", "bums" } )
747                 , is( 6 ) );
748     }
749 
750     @Test( expected = NullPointerException.class )
751     public void testInterpolate_NPE()
752     {
753         StringUtils.interpolate( null, null );
754     }
755 
756     @Test( expected = NullPointerException.class )
757     public void testInterpolate_NPE2()
758     {
759         StringUtils.interpolate( "This ${text} will get replaced", null );
760     }
761 
762     @Test
763     public void testInterpolate()
764     {
765         Map<String, String> variables = new HashMap<String, String>();
766         assertThat( StringUtils.interpolate( "This ${text} will get replaced", variables )
767                   , is( "This ${text} will get replaced" ) );
768 
769         variables.put( "text", "with a special content" );
770 
771         assertThat( StringUtils.interpolate( "This ${text} will get replaced", variables )
772                   , is( "This with a special content will get replaced" ) );
773     }
774 
775     @Test
776     public void testIsAlpha()
777     {
778         assertThat( StringUtils.isAlpha( null )
779                   , is( false ) );
780 
781         assertThat( StringUtils.isAlpha( "2" )
782                   , is( false ) );
783 
784         assertThat( StringUtils.isAlpha( "asvsdfSDF" )
785                   , is( true ) );
786 
787         assertThat( StringUtils.isAlpha( "asvsdfSDF \t " )
788                   , is( false ) );
789 
790         assertThat( StringUtils.isAlpha( "435afsafd3!" )
791                   , is( false ) );
792     }
793 
794     @Test
795     public void testIsAlphaSpace()
796     {
797         assertThat( StringUtils.isAlphaSpace( null )
798                   , is( false ) );
799 
800         assertThat( StringUtils.isAlphaSpace( "2" )
801                   , is( false ) );
802 
803         assertThat( StringUtils.isAlphaSpace( "asvsdfSDF" )
804                   , is( true ) );
805 
806         assertThat( StringUtils.isAlphaSpace( "asvsdfSDF  " )
807                   , is( true ) );
808 
809         assertThat( StringUtils.isAlphaSpace( "asvsdfSDF \t " )
810                   , is( false ) );
811 
812         assertThat( StringUtils.isAlphaSpace( "435afsafd3!" )
813                   , is( false ) );
814     }
815 
816     @Test
817     public void testIsAlphanumeric()
818     {
819         assertThat( StringUtils.isAlphanumeric( null )
820                   , is( false ) );
821 
822         assertThat( StringUtils.isAlphanumeric( "2" )
823                   , is( true ) );
824 
825         assertThat( StringUtils.isAlphanumeric( "asvsdfSDF" )
826                   , is( true ) );
827 
828         assertThat( StringUtils.isAlphanumeric( "asvsdfSDF  " )
829                   , is( false ) );
830 
831         assertThat( StringUtils.isAlphanumeric( "asvsdfSDF \t " )
832                   , is( false ) );
833 
834         assertThat( StringUtils.isAlphanumeric( "435afsafd3!" )
835                   , is( false ) );
836 
837         assertThat( StringUtils.isAlphanumeric( "435afsafd3" )
838                   , is( true ) );
839 
840         assertThat( StringUtils.isAlphanumeric( "435 " )
841                   , is( false ) );
842 
843         assertThat( StringUtils.isAlphanumeric( "435" )
844                   , is( true ) );
845     }
846 
847     @Test
848     public void testIsAlphanumericSpace()
849     {
850         assertThat( StringUtils.isAlphanumericSpace( null )
851                   , is( false ) );
852 
853         assertThat( StringUtils.isAlphanumericSpace( "2" )
854                   , is( true ) );
855 
856         assertThat( StringUtils.isAlphanumericSpace( "asvsdfSDF" )
857                   , is( true ) );
858 
859         assertThat( StringUtils.isAlphanumericSpace( "asvsdfSDF  " )
860                   , is( true ) );
861 
862         assertThat( StringUtils.isAlphanumericSpace( "asvsdfSDF \t " )
863                   , is( false ) );
864 
865         assertThat( StringUtils.isAlphanumericSpace( "435afsafd3!" )
866                   , is( false ) );
867 
868         assertThat( StringUtils.isAlphanumericSpace( "435afsafd3" )
869                   , is( true ) );
870 
871         assertThat( StringUtils.isAlphanumericSpace( "435 " )
872                   , is( true ) );
873 
874         assertThat( StringUtils.isAlphanumericSpace( "435" )
875                   , is( true ) );
876     }
877 
878     @Test
879     public void testIsBlank()
880     {
881         assertThat( StringUtils.isBlank( null )
882                   , is( true ) );
883 
884         assertThat( StringUtils.isBlank( "xx" )
885                   , is( false ) );
886 
887         assertThat( StringUtils.isBlank( "xx " )
888                   , is( false ) );
889 
890         assertThat( StringUtils.isBlank( "  " )
891                   , is( true ) );
892 
893         assertThat( StringUtils.isBlank( "  \t " )
894                   , is( true ) );
895 
896         assertThat( StringUtils.isBlank( "  \n " )
897                   , is( true ) );
898     }
899 
900 
901     @Test
902     public void testEmpty()
903     {
904         assertThat( StringUtils.isEmpty( null )
905                   , is( true ) );
906 
907         assertThat( StringUtils.isEmpty( "xx" )
908                   , is( false ) );
909 
910         assertThat( StringUtils.isEmpty( "xx " )
911                   , is( false ) );
912 
913         assertThat( StringUtils.isEmpty( "  " )
914                   , is( true ) );
915 
916         assertThat( StringUtils.isEmpty( "  \t " )
917                   , is( true ) );
918 
919         assertThat( StringUtils.isEmpty( "  \n " )
920                   , is( true ) );
921     }
922 
923     @Test
924     public void testNotBlank()
925     {
926         assertThat( StringUtils.isNotBlank( null )
927                   , is( false ) );
928 
929         assertThat( StringUtils.isNotBlank( "xx" )
930                   , is( true ) );
931 
932         assertThat( StringUtils.isNotBlank( "xx " )
933                   , is( true ) );
934 
935         assertThat( StringUtils.isNotBlank( "  " )
936                   , is( false ) );
937 
938         assertThat( StringUtils.isNotBlank( "  \t " )
939                   , is( false ) );
940 
941         assertThat( StringUtils.isNotBlank( "  \n " )
942                   , is( false ) );
943     }
944 
945     @Test
946     public void testNotEmpty()
947     {
948         assertThat( StringUtils.isNotEmpty( null )
949                   , is( false ) );
950 
951         assertThat( StringUtils.isNotEmpty( "xx" )
952                   , is( true ) );
953 
954         assertThat( StringUtils.isNotEmpty( "xx " )
955                   , is( true ) );
956 
957         assertThat( StringUtils.isNotEmpty( "  " )
958                   , is( true ) );
959 
960         assertThat( StringUtils.isNotEmpty( "" )
961                   , is( false ) );
962 
963         assertThat( StringUtils.isNotEmpty( "  \t " )
964                   , is( true ) );
965 
966         assertThat( StringUtils.isNotEmpty( "  \n " )
967                   , is( true ) );
968     }
969 
970     @Test
971     public void testIsNumeric()
972     {
973         assertThat( StringUtils.isNumeric( null )
974                   , is( false ) );
975 
976         assertThat( StringUtils.isNumeric( "2" )
977                   , is( true ) );
978 
979         assertThat( StringUtils.isNumeric( "asvsdfSDF" )
980                   , is( false ) );
981 
982         assertThat( StringUtils.isNumeric( "asvsdfSDF  " )
983                   , is( false ) );
984 
985         assertThat( StringUtils.isNumeric( "asvsdfSDF \t " )
986                   , is( false ) );
987 
988         assertThat( StringUtils.isNumeric( "435afsafd3!" )
989                   , is( false ) );
990 
991         assertThat( StringUtils.isNumeric( "435afsafd3" )
992                   , is( false ) );
993 
994         assertThat( StringUtils.isNumeric( "435 " )
995                   , is( false ) );
996 
997         assertThat( StringUtils.isNumeric( "435" )
998                   , is( true ) );
999     }
1000 
1001     @Test
1002     public void testIsWhitespace()
1003     {
1004         assertThat( StringUtils.isWhitespace( null )
1005                   , is( false ) );
1006 
1007         assertThat( StringUtils.isWhitespace( "xx" )
1008                   , is( false ) );
1009 
1010         assertThat( StringUtils.isWhitespace( "xx " )
1011                   , is( false ) );
1012 
1013         assertThat( StringUtils.isWhitespace( "  " )
1014                   , is( true ) );
1015 
1016         assertThat( StringUtils.isWhitespace( "" )
1017                   , is( true ) );
1018 
1019         assertThat( StringUtils.isWhitespace( "  \t " )
1020                   , is( true ) );
1021 
1022         assertThat( StringUtils.isWhitespace( "  \n " )
1023                   , is( true ) );
1024     }
1025 
1026     @Test( expected = NullPointerException.class )
1027     public void testJoin_Array_NPE()
1028     {
1029         StringUtils.join( ( Object[] ) null, null );
1030     }
1031 
1032     @Test
1033     public void testJoin_Array()
1034     {
1035         assertThat( StringUtils.join( new Object[0], null )
1036                   , is( "" ) );
1037 
1038         assertThat( StringUtils.join( new Object[]{ "a", "b", "c" }, null )
1039                   , is( "abc" ) );
1040 
1041         assertThat( StringUtils.join( new Object[]{ "a", "b", "c" }, "__" )
1042                   , is( "a__b__c" ) );
1043     }
1044 
1045     @Test( expected = NullPointerException.class )
1046     public void testJoin_Iterator_NPE()
1047     {
1048         StringUtils.join( (Iterator<?>) null, null );
1049     }
1050 
1051     @Test
1052     public void testJoin_Iterator()
1053     {
1054         ArrayList<String> list = new ArrayList<String>();
1055 
1056         assertThat( StringUtils.join( list.iterator(), null )
1057                   , is( "" ) );
1058 
1059         list.add( "a" );
1060         list.add( "b" );
1061         list.add( "c" );
1062 
1063         assertThat( StringUtils.join( list.iterator(), null )
1064                   , is( "abc" ) );
1065 
1066         assertThat( StringUtils.join( list.iterator(), "__" )
1067                   , is( "a__b__c" ) );
1068     }
1069 
1070     @Test
1071     public void testLastIndexOfAny()
1072     {
1073         assertThat( StringUtils.lastIndexOfAny( null, null )
1074                   , is( -1 ) );
1075 
1076         assertThat( StringUtils.lastIndexOfAny( "dings", null )
1077                   , is( -1 ) );
1078 
1079         assertThat( StringUtils.lastIndexOfAny( "dings bums boms", new String[] { "ms", " b" } )
1080                   , is( 13 ) );
1081 
1082         assertThat( StringUtils.lastIndexOfAny( "dings bums boms", new String[] { "nix", "da" } )
1083                   , is( -1 ) );
1084     }
1085 
1086     @Test( expected = IllegalArgumentException.class )
1087     public void testLeft_IAE()
1088     {
1089         StringUtils.left( null, -1 );
1090     }
1091 
1092     @Test
1093     public void testLeft()
1094     {
1095         assertThat( StringUtils.left( null, 4 )
1096                   , nullValue() );
1097 
1098         assertThat( StringUtils.left( "dingsbums", 4 )
1099                   , is( "ding" ) );
1100 
1101         assertThat( StringUtils.left( "dingsbums", 40 )
1102                   , is( "dingsbums" ) );
1103 
1104         assertThat( StringUtils.left( "dingsbums", 0 )
1105                   , is( "" ) );
1106     }
1107 
1108     @Test( expected = NullPointerException.class )
1109     public void testLeftPad1_NPE()
1110     {
1111         StringUtils.leftPad( null, 0 );
1112     }
1113 
1114     @Test
1115     public void testLeftPad1()
1116     {
1117         assertThat( StringUtils.leftPad( "dings", 0 )
1118                   , is( "dings")  );
1119 
1120         assertThat( StringUtils.leftPad( "dings", 2 )
1121                   , is( "dings")  );
1122 
1123         assertThat( StringUtils.leftPad( "dings", 10 )
1124                   , is( "     dings")  );
1125     }
1126 
1127     @Test( expected = NullPointerException.class )
1128     public void testLeftPad2_NPE1()
1129     {
1130         StringUtils.leftPad( null, 0, null );
1131     }
1132 
1133     @Test( expected = NullPointerException.class )
1134     public void testLeftPad2_NPE2()
1135     {
1136         StringUtils.leftPad( "dings", 0, null );
1137     }
1138 
1139     @Test( expected = NullPointerException.class )
1140     public void testLeftPad2_NPE3()
1141     {
1142         StringUtils.leftPad( null, 0, "*" );
1143     }
1144 
1145     @Test
1146     public void testLeftPad2()
1147     {
1148         assertThat( StringUtils.leftPad( "dings", 0, "*" )
1149                   , is( "dings") );
1150 
1151         assertThat( StringUtils.leftPad( "dings", 2, "*" )
1152                   , is( "dings") );
1153 
1154         assertThat( StringUtils.leftPad( "dings", 10, "*" )
1155                   , is( "*****dings") );
1156     }
1157 
1158     @Test
1159     public void testLowerCase()
1160     {
1161         assertThat( StringUtils.lowerCase( null )
1162                   , nullValue()  );
1163 
1164         assertThat( StringUtils.lowerCase( "dinGSbuMS" )
1165                   , is( "dingsbums" ) );
1166 
1167         assertThat( StringUtils.lowerCase( "" )
1168                   , is( "" ) );
1169 
1170     }
1171 
1172     @Test( expected = NullPointerException.class )
1173     public void testLowerCaseFirstLetter_NPE()
1174     {
1175         StringUtils.lowercaseFirstLetter( null );
1176     }
1177 
1178     @Test
1179     public void testLowerCaseFirstLetter()
1180     {
1181         assertThat( StringUtils.lowercaseFirstLetter( "Dings Bums" )
1182                   , is( "dings Bums" ) );
1183     }
1184 
1185     @Test( expected = IllegalArgumentException.class )
1186     public void testMid_NegativeLen()
1187     {
1188         StringUtils.mid( null, 0, -2 );
1189     }
1190 
1191     @Test( expected = IndexOutOfBoundsException.class )
1192     public void testMid_WrongPos()
1193     {
1194         StringUtils.mid( null, -2, 3 );
1195     }
1196 
1197     @Test
1198     public void testMid()
1199     {
1200         assertThat( StringUtils.mid( null, 0, 0 )
1201                   , nullValue() );
1202 
1203         assertThat( StringUtils.mid( "dings bums", 0, 0 )
1204                   , is( "" ) );
1205 
1206         assertThat( StringUtils.mid( "dings bums", 3, 4 )
1207                   , is( "gs b" ) );
1208     }
1209 
1210     @Test( expected = NullPointerException.class )
1211     public void testOverlayString_NPE1()
1212     {
1213         StringUtils.overlayString( null, null, 0, 0 );
1214     }
1215 
1216     @Test( expected = NullPointerException.class )
1217     public void testOverlayString_NPE2()
1218     {
1219         StringUtils.overlayString( "dings", null, 0, 0 );
1220     }
1221 
1222     @Test( expected = NullPointerException.class )
1223     public void testOverlayString_NPE3()
1224     {
1225         StringUtils.overlayString( null, "bums", 0, 0 );
1226     }
1227 
1228     @Test
1229     public void testOverlayString()
1230     {
1231         assertThat( StringUtils.overlayString( "dings", "bums", 0, 0 )
1232                   , is( "bumsdings" ) );
1233 
1234         assertThat( StringUtils.overlayString( "dings", "bums", 2, 4 )
1235                   , is( "dibumss" ) );
1236     }
1237 
1238     @Test( expected = NullPointerException.class )
1239     public void testPrechomp_NPE1()
1240     {
1241         StringUtils.prechomp( null, null );
1242     }
1243 
1244     @Test( expected = NullPointerException.class )
1245     public void testPrechomp_NPE2()
1246     {
1247         StringUtils.prechomp( "dings", null );
1248     }
1249 
1250     @Test( expected = NullPointerException.class )
1251     public void testPrechomp_NPE3()
1252     {
1253         StringUtils.prechomp( null, "bums" );
1254     }
1255 
1256     @Test
1257     public void testPrechomp()
1258     {
1259         assertThat( StringUtils.prechomp( "dings bums", " " )
1260                   , is( "bums" ) );
1261 
1262         assertThat( StringUtils.prechomp( "dings bums", "nix" )
1263                   , is( "dings bums" ) );
1264     }
1265 
1266     @Test
1267     public void testQuoteAndEscape1()
1268     {
1269         assertThat( StringUtils.quoteAndEscape( null, '+' )
1270                   , nullValue() );
1271 
1272         assertThat( StringUtils.quoteAndEscape( "", '+' )
1273                   , is( "" ) );
1274 
1275         assertThat( StringUtils.quoteAndEscape( "abc", '"' )
1276                   , is( "abc" ) );
1277 
1278         assertThat( StringUtils.quoteAndEscape( "a\"bc", '"' )
1279                   , is( "\"a\\\"bc\"" ) );
1280 
1281         assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'' )
1282                   , is( "\'a\\'bc\'" ) );
1283 
1284         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'' )
1285                   , is( "a\"bc" ) );
1286     }
1287 
1288     @Test
1289     public void testQuoteAndEscape2()
1290     {
1291         assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' } )
1292                   , nullValue() );
1293 
1294         assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' } )
1295                   , is( "" ) );
1296 
1297         assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' } )
1298                   , is( "abc" ) );
1299 
1300         assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' } )
1301                   , is( "\"a\\\"bc\"" ) );
1302 
1303         assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' } )
1304                   , is( "\'a\\'bc\'" ) );
1305 
1306         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' } )
1307                   , is( "a\"bc" ) );
1308 
1309         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' } )
1310                   , is( "\'a\"bc\'" ) );
1311     }
1312 
1313     @Test
1314     public void testQuoteAndEscape3()
1315     {
1316         assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, '\\', false )
1317                   , nullValue() );
1318 
1319         assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, '\\', false )
1320                   , is( "" ) );
1321 
1322         assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, '\\', false )
1323                   , is( "abc" ) );
1324 
1325         assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, '\\', false )
1326                   , is( "\"a\\\"bc\"" ) );
1327 
1328         assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, '\\', false )
1329                   , is( "a\'bc" ) );
1330 
1331         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, '\\', false )
1332                   , is( "a\"bc" ) );
1333 
1334         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' }, '\\', false )
1335                   , is( "\'a\\\"bc\'" ) );
1336 
1337         // with force flag
1338         assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, '\\', true )
1339                   , nullValue() );
1340 
1341         assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, '\\', true )
1342                   , is( "++" ) );
1343 
1344         assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, '\\', true )
1345                   , is( "\"abc\"" ) );
1346 
1347         assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, '\\', true )
1348                   , is( "\"a\\\"bc\"" ) );
1349 
1350         assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, '\\', true )
1351                   , is( "\'a\'bc\'" ) );
1352 
1353         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, '\\', true )
1354                   , is( "\'a\"bc\'" ) );
1355 
1356         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' }, '\\', true )
1357                   , is( "\'a\\\"bc\'" ) );
1358     }
1359 
1360     @Test
1361     public void testQuoteAndEscape4()
1362     {
1363         assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, new char[]{ '"' }, '\\', false )
1364                   , nullValue() );
1365 
1366         assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' },  new char[]{ '"' }, '\\', false )
1367                   , is( "" ) );
1368 
1369         assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', false )
1370                   , is( "abc" ) );
1371 
1372         assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', false )
1373                   , is( "\"a\\\"bc\"" ) );
1374 
1375         assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, new char[]{ '"' }, '\\', false )
1376                   , is( "a\'bc" ) );
1377 
1378         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, new char[]{ '"' }, '\\', false )
1379                   , is( "\'a\"bc\'" ) );
1380 
1381         assertThat( StringUtils.quoteAndEscape( "\'a\"bc\'", '\'', new char[]{ '\'', '"' }, new char[]{ '"' }, '\\', false )
1382                   , is( "\'a\"bc\'" ) );
1383 
1384         // with force flag
1385         assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, new char[]{ '"' }, '\\', true )
1386                   , nullValue() );
1387 
1388         assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, new char[]{ '"' }, '\\', true )
1389                   , is( "++" ) );
1390 
1391         assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', true )
1392                   , is( "\"abc\"" ) );
1393 
1394         assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', true )
1395                   , is( "\"a\\\"bc\"" ) );
1396 
1397         assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, new char[]{ '"' }, '\\', true )
1398                   , is( "\'a\'bc\'" ) );
1399 
1400         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, new char[]{ '"' }, '\\', true )
1401                   , is( "\'a\"bc\'" ) );
1402 
1403         assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' }, new char[]{ '"' }, '\\', true )
1404                   , is( "\'a\\\"bc\'" ) );
1405     }
1406 
1407     @Test( expected = NullPointerException.class )
1408     public void testRemoveAndHump_NPE1()
1409     {
1410         StringUtils.removeAndHump( null, null );
1411     }
1412 
1413     @Test( expected = NullPointerException.class )
1414     public void testRemoveAndHump_NPE2()
1415     {
1416         StringUtils.removeAndHump( "dings", null );
1417     }
1418 
1419     @Test( expected = NullPointerException.class )
1420     public void testRemoveAndHump_NPE3()
1421     {
1422         StringUtils.removeAndHump( null, "bums" );
1423     }
1424 
1425     @Test
1426     public void testRemoveAndHump()
1427     {
1428         assertThat( StringUtils.removeAndHump( "dings", "bums" )
1429                   , is( "Ding" ) );
1430 
1431         assertThat( StringUtils.removeAndHump( "this-is-it", "-" )
1432                   , is( "ThisIsIt" ) );
1433 
1434         assertThat( StringUtils.removeAndHump( "THIS-IS-IT", "-" )
1435                   , is( "THISISIT" ) );
1436 
1437     }
1438 
1439     @Test( expected = NullPointerException.class )
1440     public void testRemoveDuplicateWhitespace_NPE()
1441     {
1442         StringUtils.removeDuplicateWhitespace( null );
1443     }
1444 
1445     @Test
1446     public void testRemoveDuplicateWhitespace()
1447     {
1448         assertThat( StringUtils.removeDuplicateWhitespace( "dings" )
1449                   , is( "dings" ) );
1450 
1451         assertThat( StringUtils.removeDuplicateWhitespace( "dings bums" )
1452                   , is( "dings bums" ) );
1453 
1454         assertThat( StringUtils.removeDuplicateWhitespace( "dings  bums" )
1455                   , is( "dings bums" ) );
1456 
1457         assertThat( StringUtils.removeDuplicateWhitespace( "dings \t bums" )
1458                   , is( "dings bums" ) );
1459 
1460     }
1461 
1462     @Test( expected = NullPointerException.class )
1463     public void testRepeat_NPE()
1464     {
1465         StringUtils.repeat( null, 0 );
1466     }
1467 
1468     @Test( expected = NegativeArraySizeException.class )
1469     public void testRepeat_NegativeAmount()
1470     {
1471         StringUtils.repeat( "dings", -1 );
1472     }
1473 
1474 
1475     @Test
1476     public void testRepeat()
1477     {
1478         assertThat( StringUtils.repeat( "dings", 0 )
1479                   , is( "" ) );
1480 
1481         assertThat( StringUtils.repeat( "dings", 1 )
1482                   , is( "dings" ) );
1483 
1484         assertThat( StringUtils.repeat( "dings", 3 )
1485                   , is( "dingsdingsdings" ) );
1486     }
1487 
1488 
1489     @Test
1490     public void testReplace_char()
1491     {
1492         assertThat( StringUtils.replace(  null, 'i', 'o' )
1493                   , nullValue() );
1494 
1495         assertThat( StringUtils.replace(  "dings", 'i', 'o' )
1496                   , is( "dongs" ) );
1497 
1498         assertThat( StringUtils.replace(  "dingsbims", 'i', 'o' )
1499                   , is( "dongsboms" ) );
1500 
1501         assertThat( StringUtils.replace(  "dings", 'x', 'o' )
1502                   , is( "dings" ) );
1503     }
1504 
1505     @Test
1506     public void testReplace2_char_max()
1507     {
1508         assertThat( StringUtils.replace(  null, 'i', 'o', 0 )
1509                   , nullValue() );
1510 
1511         assertThat( StringUtils.replace(  "dingsibumsi", 'i', 'o', 3 )
1512                   , is( "dongsobumso" ) );
1513 
1514         assertThat( StringUtils.replace(  "dingsibumsi", 'i', 'o', 2 )
1515                   , is( "dongsobumsi" ) );
1516 
1517         assertThat( StringUtils.replace(  "dingsibumsi", 'i', 'o', 0 )
1518                   , is( "dongsobumso" ) );
1519 
1520         assertThat( StringUtils.replace(  "dingsibumsi", 'i', 'o', -2 )
1521                   , is( "dongsobumso" ) );
1522 
1523         assertThat( StringUtils.replace(  "dings", 'x', 'o', 2 )
1524                   , is( "dings" ) );
1525     }
1526 
1527     @Test
1528     public void testReplace_string()
1529     {
1530         assertThat( StringUtils.replace(  null, "in", "ox" )
1531                   , nullValue() );
1532 
1533         assertThat( StringUtils.replace(  "dings", "in", "ox" )
1534                   , is( "doxgs" ) );
1535 
1536         assertThat( StringUtils.replace(  "dingsbins", "in", "ox" )
1537                   , is( "doxgsboxs" ) );
1538 
1539         assertThat( StringUtils.replace(  "dings", "nin", "ox" )
1540                   , is( "dings" ) );
1541     }
1542 
1543 
1544     @Test
1545     public void testReplace2_string_max()
1546     {
1547         assertThat( StringUtils.replace(  null, "in", "ox", 0 )
1548                   , nullValue() );
1549 
1550         assertThat( StringUtils.replace(  "dingsibumsi", "si", "xo", 3 )
1551                   , is( "dingxobumxo" ) );
1552 
1553         assertThat( StringUtils.replace(  "dingsibumsi", "si", "xo", 2 )
1554                   , is( "dingxobumxo" ) );
1555 
1556         assertThat( StringUtils.replace(  "dingsibumsi", "si", "xo", 1 )
1557                   , is( "dingxobumsi" ) );
1558 
1559         assertThat( StringUtils.replace(  "dingsibumsi", "si", "xo", 0 )
1560                   , is( "dingxobumxo" ) );
1561 
1562         assertThat( StringUtils.replace(  "dingsibumsi", "si", "xo", -2 )
1563                   , is( "dingxobumxo" ) );
1564 
1565         assertThat( StringUtils.replace(  "dings", "si", "xo", 2 )
1566                   , is( "dings" ) );
1567     }
1568 
1569     @Test
1570     public void testReplaceOnce_char()
1571     {
1572         assertThat( StringUtils.replaceOnce(  null, 'i', 'o' )
1573                   , nullValue() );
1574 
1575         assertThat( StringUtils.replaceOnce(  "dingsibumsi", 'i', 'o' )
1576                   , is( "dongsibumsi" ) );
1577 
1578         assertThat( StringUtils.replaceOnce(  "dings", 'x', 'o' )
1579                   , is( "dings" ) );
1580     }
1581 
1582     @Test
1583     public void testReplaceOnce_string()
1584     {
1585         assertThat( StringUtils.replaceOnce(  null, "in", "ox" )
1586                   , nullValue() );
1587 
1588         assertThat( StringUtils.replaceOnce(  "dingsibumsi", "si", "xo" )
1589                   , is( "dingxobumsi" ) );
1590 
1591         assertThat( StringUtils.replaceOnce(  "dings", "si", "xo" )
1592                   , is( "dings" ) );
1593     }
1594 
1595     
1596     @Test
1597     public void testReverse()
1598     {
1599         assertThat( StringUtils.reverse( null )
1600                   , nullValue() );
1601 
1602         assertThat( StringUtils.reverse( "" )
1603                   , is( "" ) );
1604 
1605         assertThat( StringUtils.reverse( "dings" )
1606                   , is( "sgnid" ) );
1607 
1608         assertThat( StringUtils.reverse( "  dings " )
1609                   , is( " sgnid  " ) );
1610     }
1611 
1612     @Test( expected = NullPointerException.class )
1613     public void testReverseDelimitedString_NPE1()
1614     {
1615         StringUtils.reverseDelimitedString( null, null );
1616     }
1617 
1618     @Test( expected = NullPointerException.class )
1619     public void testReverseDelimitedString_NPE2()
1620     {
1621         StringUtils.reverseDelimitedString( null, " " );
1622     }
1623 
1624     @Test
1625     public void testReverseDelimitedString()
1626     {
1627         assertThat( StringUtils.reverseDelimitedString( "dings", null )
1628                   , is( "dings" ) );
1629 
1630         assertThat( StringUtils.reverseDelimitedString( "", " " )
1631                   , is( "" ) );
1632 
1633         assertThat( StringUtils.reverseDelimitedString( "dings", " " )
1634                   , is( "dings" ) );
1635 
1636         assertThat( StringUtils.reverseDelimitedString( "  dings ", " " )
1637                   , is( "dings" ) );
1638 
1639         assertThat( StringUtils.reverseDelimitedString( "dings bums", " " )
1640                   , is( "bums dings" ) );
1641     }
1642 
1643     @Test( expected = IllegalArgumentException.class )
1644     public void testRight_IAE1()
1645     {
1646         StringUtils.right( null, -1 );
1647     }
1648 
1649     @Test( expected = IllegalArgumentException.class )
1650     public void testRight_IAE2()
1651     {
1652         StringUtils.right( "dings", -1 );
1653     }
1654 
1655     @Test
1656     public void testRight()
1657     {
1658         assertThat( StringUtils.right( null, 0 )
1659                   , nullValue() );
1660 
1661         assertThat( StringUtils.right( "dings", 0 )
1662                   , is( "" ) );
1663 
1664         assertThat( StringUtils.right( "dings", 3 )
1665                   , is( "ngs" ) );
1666 
1667         assertThat( StringUtils.right( "dings ", 3 )
1668                   , is( "gs " ) );
1669     }
1670 
1671     @Test( expected = NullPointerException.class )
1672     public void testRightPad1_NPE()
1673     {
1674         StringUtils.rightPad( null, 0 );
1675     }
1676 
1677     @Test
1678     public void testRightPad1()
1679     {
1680         assertThat( StringUtils.rightPad( "dings", 0 )
1681                   , is( "dings" ) );
1682 
1683         assertThat( StringUtils.rightPad( "dings", 3 )
1684                   , is( "dings" ) );
1685 
1686         assertThat( StringUtils.rightPad( "dings", 10 )
1687                   , is( "dings     " ) );
1688     }
1689 
1690     @Test( expected = NullPointerException.class )
1691     public void testRightPad2_NPE1()
1692     {
1693         StringUtils.rightPad( null, 0, null );
1694     }
1695 
1696     @Test( expected = NullPointerException.class )
1697     public void testRightPad2_NPE2()
1698     {
1699         StringUtils.rightPad( "dings", 0, null );
1700     }
1701 
1702     @Test( expected = NullPointerException.class )
1703     public void testRightPad2_NPE23()
1704     {
1705         StringUtils.rightPad( null, 0, "+" );
1706     }
1707 
1708     @Test
1709     public void testRightPad2()
1710     {
1711         assertThat( StringUtils.rightPad( "dings", 0, "+" )
1712                   , is( "dings" ) );
1713 
1714         assertThat( StringUtils.rightPad( "dings", 3, "+" )
1715                   , is( "dings" ) );
1716 
1717         assertThat( StringUtils.rightPad( "dings", 10, "+" )
1718                   , is( "dings+++++" ) );
1719     }
1720 
1721 
1722     @Test( expected = NullPointerException.class )
1723     public void testSplit1_NPE()
1724     {
1725         StringUtils.split( null );
1726     }
1727 
1728     @Test
1729     public void testSplit1()
1730     {
1731         assertThat( StringUtils.split( "dings" )
1732                   , is( new String[]{ "dings" } ) );
1733 
1734         assertThat( StringUtils.split( "dings bums" )
1735                   , is( new String[]{ "dings", "bums" } ) );
1736     }
1737 
1738     @Test( expected = NullPointerException.class )
1739     public void testSplit2_NPE1()
1740     {
1741         StringUtils.split( null, null );
1742     }
1743 
1744     @Test( expected = NullPointerException.class )
1745     public void testSplit2_NPE2()
1746     {
1747         StringUtils.split( null, " " );
1748     }
1749 
1750     @Test
1751     public void testSplit2()
1752     {
1753         assertThat( StringUtils.split( "dings", null )
1754                   , is( new String[]{ "dings" } ) );
1755 
1756         assertThat( StringUtils.split( "dings bums", null )
1757                   , is( new String[]{ "dings", "bums" } ) );
1758 
1759         assertThat( StringUtils.split( "dings", "+" )
1760                   , is( new String[]{ "dings" } ) );
1761 
1762         assertThat( StringUtils.split( "dings+bums", "+" )
1763                   , is( new String[]{ "dings", "bums" } ) );
1764     }
1765 
1766     @Test( expected = NullPointerException.class )
1767     public void testSplit3_NPE1()
1768     {
1769         StringUtils.split( null, null, 1 );
1770     }
1771 
1772     @Test( expected = NullPointerException.class )
1773     public void testSplit3_NPE2()
1774     {
1775         StringUtils.split( null, " ", 1 );
1776     }
1777 
1778     @Test
1779     public void testSplit3()
1780     {
1781         assertThat( StringUtils.split( "dings", null, 3 )
1782                   , is( new String[]{ "dings" } ) );
1783 
1784         assertThat( StringUtils.split( "dings bums", null, 3 )
1785                   , is( new String[]{ "dings", "bums" } ) );
1786 
1787         assertThat( StringUtils.split( "dings", "+", 3 )
1788                   , is( new String[]{ "dings" } )  );
1789 
1790         assertThat( StringUtils.split( "dings+bums", "+", 3 )
1791                   , is( new String[]{ "dings", "bums" } ) );
1792 
1793         assertThat( StringUtils.split( "dings+bums", "+", 1 )
1794                   , is( new String[]{ "dings+bums" } )  );
1795 
1796         assertThat( StringUtils.split( "dings+bums", "+", 0 )
1797                   , is( new String[]{ "dings", "bums" } ) );
1798 
1799         assertThat( StringUtils.split( "dings+bums", "+", -5 )
1800                   , is( new String[]{ "dings", "bums" } ) );
1801 
1802     }
1803 
1804 
1805     @Test
1806     public void testStrip1()
1807     {
1808         assertThat( StringUtils.strip( null )
1809                   , nullValue() );
1810 
1811         assertThat( StringUtils.strip( "dings" )
1812                   , is( "dings" ) );
1813 
1814         assertThat( StringUtils.strip( "  dings \t " )
1815                   , is( "dings" ) );
1816     }
1817 
1818     @Test
1819     public void testStrip2()
1820     {
1821         assertThat( StringUtils.strip( null, " " )
1822                   , nullValue() );
1823 
1824         assertThat( StringUtils.strip( null, null )
1825                   , nullValue() );
1826 
1827         assertThat( StringUtils.strip( "dings", " " )
1828                   , is( "dings" ) );
1829 
1830         assertThat( StringUtils.strip( "  dings \t ", " " )
1831                   , is( "dings \t" ) );
1832     }
1833 
1834     @Test
1835     public void testStripAll1()
1836     {
1837         assertThat( StringUtils.stripAll( null )
1838                   , nullValue() );
1839 
1840         assertThat( StringUtils.stripAll( new String[]{} )
1841                   , is( new String[]{} ) );
1842 
1843         assertThat( StringUtils.stripAll( new String[]{ "dings" } )
1844                   , is( new String[]{ "dings" } ) );
1845 
1846         assertThat( StringUtils.stripAll( new String[]{ " dings ", "  bums \t  " } )
1847                   , is( new String[]{ "dings", "bums" } ) );
1848     }
1849 
1850     @Test
1851     public void testStripAll2()
1852     {
1853         assertThat( StringUtils.stripAll( null, " " )
1854                   , nullValue() );
1855 
1856         assertThat( StringUtils.stripAll( new String[]{}, " " )
1857                   , is( new String[]{} ) );
1858 
1859         assertThat( StringUtils.stripAll( new String[]{ "dings" }, " " )
1860                   , is( new String[]{ "dings" } ) );
1861 
1862         assertThat( StringUtils.stripAll( new String[]{ " dings ", "  bums \t  " }, " " )
1863                   , is( new String[]{ "dings", "bums \t" } ) );
1864     }
1865 
1866     @Test
1867     public void testStripEnd()
1868     {
1869         assertThat( StringUtils.stripEnd( null, null )
1870                   , nullValue() );
1871 
1872         assertThat( StringUtils.stripEnd( "dings", null )
1873                   , is( "dings" ) );
1874 
1875         assertThat( StringUtils.stripEnd( "  dings \t ", null )
1876                   , is( "  dings" ) );
1877 
1878         assertThat( StringUtils.stripEnd( null, " " )
1879                   , nullValue() );
1880 
1881         assertThat( StringUtils.stripEnd( "dings", " " )
1882                   , is( "dings" ) );
1883 
1884         assertThat( StringUtils.stripEnd( "  dings \t ", " " )
1885                   , is( "  dings \t" ) );
1886     }
1887 
1888     @Test
1889     public void testStripStart()
1890     {
1891         assertThat( StringUtils.stripStart( null, null )
1892                   , nullValue() );
1893 
1894         assertThat( StringUtils.stripStart( "dings", null )
1895                   , is( "dings" ) );
1896 
1897         assertThat( StringUtils.stripStart( "  dings \t ", null )
1898                   , is( "dings \t " ) );
1899 
1900         assertThat( StringUtils.stripStart( null, " " )
1901                   , nullValue() );
1902 
1903         assertThat( StringUtils.stripStart( "dings", " " )
1904                   , is( "dings" ) );
1905 
1906         assertThat( StringUtils.stripStart( "  \t dings \t ", " " )
1907                   , is( "\t dings \t " ) );
1908     }
1909 
1910     @Test
1911     public void testSubstring1()
1912     {
1913         assertThat( StringUtils.substring( null, 0 )
1914                   , nullValue() );
1915         assertThat( StringUtils.substring( null, -3 )
1916                   , nullValue() );
1917 
1918         assertThat( StringUtils.substring( "dings", 2 )
1919                   , is( "ngs" ) );
1920 
1921         assertThat( StringUtils.substring( "dings", -2 )
1922                   , is( "gs" ) );
1923 
1924         assertThat( StringUtils.substring( "dings", 20 )
1925                   , is( "" ) );
1926     }
1927 
1928     @Test
1929     public void testSubstring2()
1930     {
1931         assertThat( StringUtils.substring( null, 0, 2 )
1932                   , nullValue() );
1933 
1934         assertThat( StringUtils.substring( null, -3, 0 )
1935                   , nullValue() );
1936 
1937         assertThat( StringUtils.substring( "dings", 2, 4 )
1938                   , is( "ng" ) );
1939 
1940         assertThat( StringUtils.substring( "dings", -2, 4 )
1941                   , is( "g" ) );
1942 
1943         assertThat( StringUtils.substring( "dings", 20, 23 )
1944                   , is( "" ) );
1945 
1946         assertThat( StringUtils.substring( "dings", 4, 2 )
1947                   , is( "" ) );
1948     }
1949 
1950     @Test
1951     public void testSwapCase()
1952     {
1953         assertThat( StringUtils.swapCase( null )
1954                   , nullValue() );
1955 
1956         assertThat( StringUtils.swapCase( "dings" )
1957                   , is( "DINGS" ) );
1958 
1959         assertThat( StringUtils.swapCase( "DinGs" )
1960                   , is( "dINgS" ) );
1961 
1962     }
1963 
1964     @Test
1965     public void testTrim()
1966     {
1967         assertThat( StringUtils.trim( null )
1968                 , nullValue() );
1969 
1970         assertThat( StringUtils.trim( "   " )
1971                   , is( "" ) );
1972 
1973         assertThat( StringUtils.trim( "  c " )
1974                   , is( "c" ) );
1975 
1976         assertThat( StringUtils.trim( "  dings \n  " )
1977                   , is( "dings" ) );
1978     }
1979 
1980     @Test
1981     public void testUncapitalise()
1982     {
1983         assertThat( StringUtils.uncapitalise( null )
1984                 , nullValue() );
1985 
1986         assertThat( StringUtils.uncapitalise( "   " )
1987                   , is( "   " ) );
1988 
1989         assertThat( StringUtils.uncapitalise( "dings" )
1990                   , is( "dings" ) );
1991 
1992         assertThat( StringUtils.uncapitalise( "Dings" )
1993                   , is( "dings" ) );
1994 
1995         assertThat( StringUtils.uncapitalise( "DINGS" )
1996                   , is( "dINGS" ) );
1997     }
1998 
1999     @Test
2000     public void testUncapitaliseAllWords()
2001     {
2002         assertThat( StringUtils.uncapitaliseAllWords( null )
2003                 , nullValue() );
2004 
2005         assertThat( StringUtils.uncapitaliseAllWords( "   " )
2006                   , is( "   " ) );
2007 
2008         assertThat( StringUtils.uncapitaliseAllWords( "dings bums" )
2009                   , is( "dings bums" ) );
2010 
2011         assertThat( StringUtils.uncapitaliseAllWords( "Dings Bums" )
2012                   , is( "dings bums" ) );
2013 
2014         assertThat( StringUtils.uncapitaliseAllWords( "DINGS Bums" )
2015                   , is( "dINGS bums" ) );
2016     }
2017 
2018     @Test
2019     public void testUnifyLineSeparators1()
2020     {
2021         String sls = System.getProperty( "line.separator" );
2022 
2023         assertThat( StringUtils.unifyLineSeparators( null )
2024                 , nullValue() );
2025 
2026         assertThat( StringUtils.unifyLineSeparators( "   " )
2027                   , is( "   " ) );
2028 
2029         assertThat( StringUtils.unifyLineSeparators( "dings\nbums\r\ndongs" )
2030                   , is( "dings" + sls + "bums" + sls + "dongs") );
2031     }
2032 
2033     @Test
2034     public void testUnifyLineSeparators2()
2035     {
2036         assertThat( StringUtils.unifyLineSeparators( null, "\n" )
2037                 , nullValue() );
2038 
2039         assertThat( StringUtils.unifyLineSeparators( "   ", "\n" )
2040                   , is( "   " ) );
2041 
2042         assertThat( StringUtils.unifyLineSeparators( "   ", null )  // takes the sytem line separator
2043                   , is( "   " ) );
2044 
2045         assertThat( StringUtils.unifyLineSeparators( "dings\nbums\r\ndongs", "\n" )
2046                   , is( "dings\nbums\ndongs" ) );
2047     }
2048 
2049     @Test
2050     public void testUppercase()
2051     {
2052         assertThat( StringUtils.upperCase( null )
2053                 , nullValue() );
2054 
2055         assertThat( StringUtils.upperCase( "   " )
2056                   , is( "   " ) );
2057 
2058         assertThat( StringUtils.upperCase( "" )
2059                   , is( "" ) );
2060 
2061         assertThat( StringUtils.upperCase( "dings" )
2062                   , is( "DINGS" ) );
2063 
2064     }
2065 
2066 
2067 }