View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.utils;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.Iterator;
24  import java.util.Map;
25  
26  import org.junit.Test;
27  
28  import static org.hamcrest.CoreMatchers.is;
29  import static org.hamcrest.CoreMatchers.nullValue;
30  import static org.hamcrest.MatcherAssert.assertThat;
31  
32  /**
33   * Test the {@link StringUtils} class.
34   *
35   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
36   */
37  public class StringUtilsTest {
38  
39      @Test(expected = NullPointerException.class)
40      public void testAbbreviate_NPE() {
41          assertThat(StringUtils.abbreviate(null, 10), nullValue());
42      }
43  
44      @Test(expected = IllegalArgumentException.class)
45      public void testAbbreviate_MinLength() {
46          assertThat(StringUtils.abbreviate("This is a longtext", 3), is("T"));
47      }
48  
49      @Test
50      public void testAbbreviate() {
51          assertThat(StringUtils.abbreviate("This is a longtext", 10), is("This is..."));
52  
53          assertThat(StringUtils.abbreviate("This is a longtext", 50), is("This is a longtext"));
54      }
55  
56      @Test(expected = NullPointerException.class)
57      public void testAbbreviate_Offset_NPE() {
58          assertThat(StringUtils.abbreviate(null, 10, 20), nullValue());
59      }
60  
61      @Test(expected = IllegalArgumentException.class)
62      public void testAbbreviate_Offset_MinLength() {
63          assertThat(StringUtils.abbreviate("This is a longtext", 10, 3), is("T"));
64      }
65  
66      @Test
67      public void testAbbreviate_Offset() {
68          assertThat(StringUtils.abbreviate("This is a longtext", 5, 10), is("...is a..."));
69  
70          assertThat(StringUtils.abbreviate("This is a longtext", 10, 20), is("This is a longtext"));
71  
72          assertThat(StringUtils.abbreviate("This is a longtext", 50, 20), is("This is a longtext"));
73      }
74  
75      @Test(expected = NullPointerException.class)
76      public void testAddAndDeHump_NPE() {
77          StringUtils.addAndDeHump(null);
78      }
79  
80      @Test
81      public void testAddAndDeHump() {
82          assertThat(StringUtils.addAndDeHump("lalala"), is("lalala"));
83  
84          assertThat(StringUtils.addAndDeHump("LaLaLa"), is("la-la-la"));
85  
86          assertThat(StringUtils.addAndDeHump("ALLUPPER"), is("a-l-l-u-p-p-e-r"));
87      }
88  
89      @Test
90      public void testCapitalise() {
91          assertThat(StringUtils.capitalise(null), nullValue());
92  
93          assertThat(StringUtils.capitalise("startBig"), is("StartBig"));
94      }
95  
96      @Test
97      public void testCapitaliseAllWords() {
98          assertThat(StringUtils.capitaliseAllWords(null), nullValue());
99  
100         assertThat(StringUtils.capitaliseAllWords("start all big"), is("Start All Big"));
101     }
102 
103     @Test(expected = NullPointerException.class)
104     public void testCapitalizeFirstLetter_NPE() {
105         assertThat(StringUtils.capitalizeFirstLetter(null), nullValue());
106     }
107 
108     @Test
109     public void testCapitalizeFirstLetter() {
110         assertThat(StringUtils.capitalizeFirstLetter("Dings"), is("Dings"));
111 
112         assertThat(StringUtils.capitalizeFirstLetter("  dings"), is("  dings"));
113 
114         assertThat(StringUtils.capitalizeFirstLetter("start all big"), is("Start all big"));
115     }
116 
117     @Test(expected = NullPointerException.class)
118     public void testCenter_NPE() {
119         StringUtils.center(null, 20);
120     }
121 
122     @Test
123     public void testCenter() {
124         assertThat(StringUtils.center("centerMe", 20), is("      centerMe      "));
125 
126         assertThat(StringUtils.center("centerMe", 4), is("centerMe"));
127 
128         assertThat(StringUtils.center("        centerMe", 20), is("          centerMe  "));
129     }
130 
131     @Test(expected = NullPointerException.class)
132     public void testCenter_Delim_NPE() {
133         StringUtils.center(null, 20, "*");
134     }
135 
136     @Test
137     public void testCenter_Delim() {
138         assertThat(StringUtils.center("centerMe", 20, "*"), is("******centerMe******"));
139 
140         assertThat(StringUtils.center("centerMe", 4, "*"), is("centerMe"));
141 
142         assertThat(StringUtils.center("        centerMe", 20, "*"), is("**        centerMe**"));
143     }
144 
145     @Test(expected = NullPointerException.class)
146     public void testChomp_NPE() {
147         StringUtils.chomp(null);
148     }
149 
150     @Test
151     public void testChomp() {
152         assertThat(StringUtils.chomp("dings"), is("dings"));
153 
154         assertThat(StringUtils.chomp("dings\n"), is("dings"));
155 
156         assertThat(StringUtils.chomp("dings\nbums"), is("dings"));
157 
158         assertThat(StringUtils.chomp("dings\nbums\ndongs"), is("dings\nbums"));
159     }
160 
161     @Test(expected = NullPointerException.class)
162     public void testChomp_Delim_NPE() {
163         StringUtils.chomp(null, "+");
164     }
165 
166     @Test
167     public void testChomp_Delim() {
168         assertThat(StringUtils.chomp("dings", "+"), is("dings"));
169 
170         assertThat(StringUtils.chomp("dings+", "+"), is("dings"));
171 
172         assertThat(StringUtils.chomp("dings+bums", "+"), is("dings"));
173 
174         assertThat(StringUtils.chomp("dings+bums+dongs", "+"), is("dings+bums"));
175     }
176 
177     @Test(expected = NullPointerException.class)
178     public void testChompLast_NPE() {
179         StringUtils.chompLast(null);
180     }
181 
182     @Test
183     public void testChompLast() {
184         assertThat(StringUtils.chompLast("dings"), is("dings"));
185 
186         assertThat(StringUtils.chompLast("\n"), is(""));
187 
188         assertThat(StringUtils.chompLast("dings\n"), is("dings"));
189 
190         assertThat(StringUtils.chompLast("dings\nbums"), is("dings\nbums"));
191 
192         assertThat(StringUtils.chompLast("dings\nbums\ndongs\n"), is("dings\nbums\ndongs"));
193     }
194 
195     @Test(expected = NullPointerException.class)
196     public void testChompLast_Delim_NPE() {
197         StringUtils.chompLast(null, "+");
198     }
199 
200     @Test
201     public void testChompLast_Delim() {
202         assertThat(StringUtils.chompLast("dings", "+"), is("dings"));
203 
204         assertThat(StringUtils.chompLast("+", "+"), is(""));
205 
206         assertThat(StringUtils.chompLast("dings+", "+"), is("dings"));
207 
208         assertThat(StringUtils.chompLast("dings+bums", "+"), is("dings+bums"));
209 
210         assertThat(StringUtils.chompLast("dings+bums+dongs+", "+"), is("dings+bums+dongs"));
211     }
212 
213     @Test(expected = NullPointerException.class)
214     public void testChop_NPE() {
215         StringUtils.chop(null);
216     }
217 
218     @Test
219     public void testChop() {
220         assertThat(StringUtils.chop("dings"), is("ding"));
221 
222         assertThat(StringUtils.chop("x"), is(""));
223 
224         assertThat(StringUtils.chop("dings\n"), is("dings"));
225 
226         assertThat(StringUtils.chop("dings\r\n"), is("dings"));
227 
228         assertThat(StringUtils.chop("dings\n\r"), is("dings\n"));
229     }
230 
231     @Test(expected = NullPointerException.class)
232     public void testChopNewline_NPE() {
233         StringUtils.chopNewline(null);
234     }
235 
236     @Test
237     public void testChopNewline() {
238         assertThat(StringUtils.chopNewline("dings"), is("dings"));
239 
240         assertThat(StringUtils.chopNewline("x"), is("x"));
241 
242         assertThat(StringUtils.chopNewline("dings\n"), is("dings"));
243 
244         assertThat(StringUtils.chopNewline("dings\r\n"), is("dings"));
245 
246         assertThat(StringUtils.chopNewline("dings\n\r"), is("dings\n\r"));
247     }
248 
249     @Test
250     public void testClean() {
251         assertThat(StringUtils.clean(null), is(""));
252 
253         assertThat(StringUtils.clean("   "), is(""));
254 
255         assertThat(StringUtils.clean("  c "), is("c"));
256 
257         assertThat(StringUtils.clean("  dings \n  "), is("dings"));
258     }
259 
260     @Test(expected = NullPointerException.class)
261     public void testConcatenate_NPE() {
262         StringUtils.concatenate(null);
263     }
264 
265     @Test
266     public void testConcatenate() {
267         assertThat(StringUtils.concatenate(new String[0]), is(""));
268 
269         assertThat(StringUtils.concatenate(new String[] {"x"}), is("x"));
270 
271         assertThat(StringUtils.concatenate(new String[] {"x", "y", "z"}), is("xyz"));
272     }
273 
274     @Test
275     public void testContains_String() {
276         assertThat(StringUtils.contains(null, null), is(false));
277 
278         assertThat(StringUtils.contains(null, "string"), is(false));
279 
280         assertThat(StringUtils.contains("string", null), is(false));
281 
282         assertThat(StringUtils.contains("string", ""), is(true));
283 
284         assertThat(StringUtils.contains("string", "in"), is(true));
285 
286         assertThat(StringUtils.contains("string", "IN"), is(false));
287     }
288 
289     @Test
290     public void testContains_Char() {
291         assertThat(StringUtils.contains(null, 'c'), is(false));
292 
293         assertThat(StringUtils.contains("string", "c"), is(false));
294 
295         assertThat(StringUtils.contains("string", ""), is(true));
296 
297         assertThat(StringUtils.contains("string", "r"), is(true));
298 
299         assertThat(StringUtils.contains("string", "R"), is(false));
300     }
301 
302     @Test(expected = NullPointerException.class)
303     public void testCountMatches_NPE() {
304         StringUtils.countMatches(null, null);
305     }
306 
307     @Test(expected = NullPointerException.class)
308     public void testCountMatches_NPE2() {
309         StringUtils.countMatches("this is it", null);
310     }
311 
312     @Test
313     public void testCountMatches() {
314         assertThat(StringUtils.countMatches(null, "is"), is(0));
315 
316         assertThat(StringUtils.countMatches("this is it", "is"), is(2));
317 
318         assertThat(StringUtils.countMatches("this is it", "notincluded"), is(0));
319     }
320 
321     @Test
322     public void testDefaultString() {
323         assertThat(StringUtils.defaultString(null), is(""));
324 
325         assertThat(StringUtils.defaultString("dings"), is("dings"));
326     }
327 
328     @Test
329     public void testDefaultString_defaultValue() {
330         assertThat(StringUtils.defaultString(null, "defaultValue"), is("defaultValue"));
331 
332         assertThat(StringUtils.defaultString("dings", "defaultValue"), is("dings"));
333     }
334 
335     @Test(expected = NullPointerException.class)
336     public void testDeleteWhitespace_NPE() {
337         StringUtils.deleteWhitespace(null);
338     }
339 
340     @Test
341     public void testDeleteWhitespace() {
342         assertThat(StringUtils.deleteWhitespace(" \t  \n"), is(""));
343 
344         assertThat(StringUtils.deleteWhitespace(" \t  \b \n"), is("\b"));
345 
346         assertThat(StringUtils.deleteWhitespace("dings"), is("dings"));
347 
348         assertThat(StringUtils.deleteWhitespace("\n  dings \t "), is("dings"));
349     }
350 
351     @Test(expected = NullPointerException.class)
352     public void testDifference_NPE() {
353         StringUtils.difference(null, null);
354     }
355 
356     @Test(expected = NullPointerException.class)
357     public void testDifference_NPE2() {
358         StringUtils.difference(null, "another");
359     }
360 
361     @Test(expected = NullPointerException.class)
362     public void testDifference_NPE3() {
363         StringUtils.difference("this", null);
364     }
365 
366     @Test
367     public void testDifference() {
368         assertThat(StringUtils.difference("this", "another"), is("another"));
369 
370         assertThat(StringUtils.difference("I am human", "I am a robot"), is("a robot"));
371 
372         assertThat(StringUtils.difference("I am human", "I AM a robot"), is("AM a robot"));
373     }
374 
375     @Test(expected = NullPointerException.class)
376     public void testDifferenceAt_NPE() {
377         StringUtils.differenceAt(null, null);
378     }
379 
380     @Test(expected = NullPointerException.class)
381     public void testDifferenceAt_NPE2() {
382         StringUtils.differenceAt("test", null);
383     }
384 
385     @Test(expected = NullPointerException.class)
386     public void testDifferenceAt_NPE3() {
387         StringUtils.differenceAt(null, "test");
388     }
389 
390     @Test
391     public void testDifferenceAt() {
392         assertThat(StringUtils.differenceAt("this", "another"), is(0));
393 
394         assertThat(StringUtils.differenceAt("I am human", "I am a robot"), is(5));
395 
396         assertThat(StringUtils.differenceAt("I am human", "I AM a robot"), is(2));
397     }
398 
399     @Test
400     public void testEndsWithIgnoreCase() {
401         assertThat(StringUtils.endsWithIgnoreCase(null, null), is(false));
402 
403         assertThat(StringUtils.endsWithIgnoreCase(null, "string"), is(false));
404 
405         assertThat(StringUtils.endsWithIgnoreCase("string", null), is(false));
406 
407         assertThat(StringUtils.endsWithIgnoreCase("string", "ing"), is(true));
408 
409         assertThat(StringUtils.endsWithIgnoreCase("string", "a string"), is(false));
410 
411         assertThat(StringUtils.endsWithIgnoreCase("string", "str"), is(false));
412     }
413 
414     @Test
415     public void testEquals() {
416         assertThat(StringUtils.equals(null, null), is(true));
417 
418         assertThat(StringUtils.equals("x", null), is(false));
419 
420         assertThat(StringUtils.equals(null, "x"), is(false));
421 
422         assertThat(StringUtils.equals("X", "x"), is(false));
423 
424         assertThat(StringUtils.equals("dings", "dings"), is(true));
425     }
426 
427     @Test
428     public void testEqualsIgnoreCase() {
429         assertThat(StringUtils.equalsIgnoreCase(null, null), is(true));
430 
431         assertThat(StringUtils.equalsIgnoreCase("x", null), is(false));
432 
433         assertThat(StringUtils.equalsIgnoreCase(null, "x"), is(false));
434 
435         assertThat(StringUtils.equalsIgnoreCase("X", "x"), is(true));
436 
437         assertThat(StringUtils.equalsIgnoreCase("dings", "dings"), is(true));
438 
439         assertThat(StringUtils.equalsIgnoreCase("dings", "diNGs"), is(true));
440     }
441 
442     @Test(expected = NullPointerException.class)
443     public void testEscape_NPE() {
444         StringUtils.escape(null);
445     }
446 
447     @Test
448     public void testEscape() {
449         assertThat(StringUtils.escape("dings"), is("dings"));
450 
451         assertThat(StringUtils.escape("dings\tbums"), is("dings\\tbums"));
452 
453         assertThat(StringUtils.escape("dings\nbums"), is("dings\\nbums"));
454     }
455 
456     @Test
457     public void testEscape2() {
458         assertThat(StringUtils.escape(null, null, '#'), nullValue());
459 
460         assertThat(StringUtils.escape("dings", new char[] {'\t', '\b'}, '+'), is("dings"));
461 
462         assertThat(StringUtils.escape("dings\tbums", new char[] {'\t', '\b'}, '+'), is("dings+\tbums"));
463 
464         assertThat(StringUtils.escape("dings\nbums", new char[] {'\t', '\b'}, '+'), is("dings\nbums"));
465         assertThat(StringUtils.escape("dings\bbums", new char[] {'\t', '\b'}, '+'), is("dings+\bbums"));
466     }
467 
468     @Test(expected = NullPointerException.class)
469     public void testGetChomp_NPE1() {
470         StringUtils.getChomp(null, null);
471     }
472 
473     @Test(expected = NullPointerException.class)
474     public void testGetChomp_NPE2() {
475         StringUtils.getChomp("dings", null);
476     }
477 
478     @Test(expected = NullPointerException.class)
479     public void testGetChomp_NPE3() {
480         StringUtils.getChomp(null, "dings");
481     }
482 
483     @Test
484     public void testGetChomp() {
485         assertThat(StringUtils.getChomp("dings-bums", "-"), is("-bums"));
486 
487         assertThat(StringUtils.getChomp("dings-", "-"), is("-"));
488 
489         assertThat(StringUtils.getChomp("dingsbums", "-"), is(""));
490     }
491 
492     @Test(expected = NullPointerException.class)
493     public void testGetNestedString_NPE() {
494         assertThat(StringUtils.getNestedString("  +dings+ ", null), nullValue());
495     }
496 
497     @Test
498     public void testGetNestedString() {
499         assertThat(StringUtils.getNestedString(null, null), nullValue());
500 
501         assertThat(StringUtils.getNestedString("  +dings+ ", "+"), is("dings"));
502 
503         assertThat(StringUtils.getNestedString("  +dings+ ", "not"), nullValue());
504     }
505 
506     @Test(expected = NullPointerException.class)
507     public void testGetNestedString2_NPE1() {
508         assertThat(StringUtils.getNestedString("  +dings+ ", null, null), nullValue());
509     }
510 
511     @Test(expected = NullPointerException.class)
512     public void testGetNestedString2_NPE2() {
513         assertThat(StringUtils.getNestedString("  +dings+ ", null, "neither"), nullValue());
514     }
515 
516     @Test
517     public void testGetNestedString2() {
518         assertThat(StringUtils.getNestedString(null, null, null), nullValue());
519 
520         assertThat(StringUtils.getNestedString("  +dings+ ", "not", null), nullValue());
521 
522         assertThat(StringUtils.getNestedString("  +dings- ", "+", "-"), is("dings"));
523 
524         assertThat(StringUtils.getNestedString("  +dings+ ", "not", "neither"), nullValue());
525     }
526 
527     @Test(expected = NullPointerException.class)
528     public void testGetPrechomp_NPE1() {
529         StringUtils.getPrechomp(null, null);
530     }
531 
532     @Test(expected = NullPointerException.class)
533     public void testGetPrechomp_NPE2() {
534         StringUtils.getPrechomp(null, "bums");
535     }
536 
537     @Test
538     public void testGetPrechomp() {
539         assertThat(StringUtils.getPrechomp("dings bums dongs", "bums"), is("dings bums"));
540 
541         assertThat(StringUtils.getPrechomp("dings bums dongs", "non"), is(""));
542     }
543 
544     @Test
545     public void testIndexOfAny() {
546         assertThat(StringUtils.indexOfAny(null, null), is(-1));
547 
548         assertThat(StringUtils.indexOfAny("dings", null), is(-1));
549 
550         assertThat(StringUtils.indexOfAny(null, new String[] {}), is(-1));
551 
552         assertThat(StringUtils.indexOfAny("dings bums dongs", new String[] {"knuff", "bums"}), is(6));
553     }
554 
555     @Test(expected = NullPointerException.class)
556     public void testInterpolate_NPE() {
557         StringUtils.interpolate(null, null);
558     }
559 
560     @Test(expected = NullPointerException.class)
561     public void testInterpolate_NPE2() {
562         StringUtils.interpolate("This ${text} will get replaced", null);
563     }
564 
565     @Test
566     public void testInterpolate() {
567         Map<String, String> variables = new HashMap<String, String>();
568         assertThat(
569                 StringUtils.interpolate("This ${text} will get replaced", variables),
570                 is("This ${text} will get replaced"));
571 
572         variables.put("text", "with a special content");
573 
574         assertThat(
575                 StringUtils.interpolate("This ${text} will get replaced", variables),
576                 is("This with a special content will get replaced"));
577     }
578 
579     @Test
580     public void testIsAlpha() {
581         assertThat(StringUtils.isAlpha(null), is(false));
582 
583         assertThat(StringUtils.isAlpha("2"), is(false));
584 
585         assertThat(StringUtils.isAlpha("asvsdfSDF"), is(true));
586 
587         assertThat(StringUtils.isAlpha("asvsdfSDF \t "), is(false));
588 
589         assertThat(StringUtils.isAlpha("435afsafd3!"), is(false));
590     }
591 
592     @Test
593     public void testIsAlphaSpace() {
594         assertThat(StringUtils.isAlphaSpace(null), is(false));
595 
596         assertThat(StringUtils.isAlphaSpace("2"), is(false));
597 
598         assertThat(StringUtils.isAlphaSpace("asvsdfSDF"), is(true));
599 
600         assertThat(StringUtils.isAlphaSpace("asvsdfSDF  "), is(true));
601 
602         assertThat(StringUtils.isAlphaSpace("asvsdfSDF \t "), is(false));
603 
604         assertThat(StringUtils.isAlphaSpace("435afsafd3!"), is(false));
605     }
606 
607     @Test
608     public void testIsAlphanumeric() {
609         assertThat(StringUtils.isAlphanumeric(null), is(false));
610 
611         assertThat(StringUtils.isAlphanumeric("2"), is(true));
612 
613         assertThat(StringUtils.isAlphanumeric("asvsdfSDF"), is(true));
614 
615         assertThat(StringUtils.isAlphanumeric("asvsdfSDF  "), is(false));
616 
617         assertThat(StringUtils.isAlphanumeric("asvsdfSDF \t "), is(false));
618 
619         assertThat(StringUtils.isAlphanumeric("435afsafd3!"), is(false));
620 
621         assertThat(StringUtils.isAlphanumeric("435afsafd3"), is(true));
622 
623         assertThat(StringUtils.isAlphanumeric("435 "), is(false));
624 
625         assertThat(StringUtils.isAlphanumeric("435"), is(true));
626     }
627 
628     @Test
629     public void testIsAlphanumericSpace() {
630         assertThat(StringUtils.isAlphanumericSpace(null), is(false));
631 
632         assertThat(StringUtils.isAlphanumericSpace("2"), is(true));
633 
634         assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF"), is(true));
635 
636         assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF  "), is(true));
637 
638         assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF \t "), is(false));
639 
640         assertThat(StringUtils.isAlphanumericSpace("435afsafd3!"), is(false));
641 
642         assertThat(StringUtils.isAlphanumericSpace("435afsafd3"), is(true));
643 
644         assertThat(StringUtils.isAlphanumericSpace("435 "), is(true));
645 
646         assertThat(StringUtils.isAlphanumericSpace("435"), is(true));
647     }
648 
649     @Test
650     public void testIsBlank() {
651         assertThat(StringUtils.isBlank(null), is(true));
652 
653         assertThat(StringUtils.isBlank("xx"), is(false));
654 
655         assertThat(StringUtils.isBlank("xx "), is(false));
656 
657         assertThat(StringUtils.isBlank("  "), is(true));
658 
659         assertThat(StringUtils.isBlank("  \t "), is(true));
660 
661         assertThat(StringUtils.isBlank("  \n "), is(true));
662     }
663 
664     @Test
665     public void testEmpty() {
666         assertThat(StringUtils.isEmpty(null), is(true));
667 
668         assertThat(StringUtils.isEmpty("xx"), is(false));
669 
670         assertThat(StringUtils.isEmpty("xx "), is(false));
671 
672         assertThat(StringUtils.isEmpty("  "), is(true));
673 
674         assertThat(StringUtils.isEmpty("  \t "), is(true));
675 
676         assertThat(StringUtils.isEmpty("  \n "), is(true));
677     }
678 
679     @Test
680     public void testNotBlank() {
681         assertThat(StringUtils.isNotBlank(null), is(false));
682 
683         assertThat(StringUtils.isNotBlank("xx"), is(true));
684 
685         assertThat(StringUtils.isNotBlank("xx "), is(true));
686 
687         assertThat(StringUtils.isNotBlank("  "), is(false));
688 
689         assertThat(StringUtils.isNotBlank("  \t "), is(false));
690 
691         assertThat(StringUtils.isNotBlank("  \n "), is(false));
692     }
693 
694     @Test
695     public void testNotEmpty() {
696         assertThat(StringUtils.isNotEmpty(null), is(false));
697 
698         assertThat(StringUtils.isNotEmpty("xx"), is(true));
699 
700         assertThat(StringUtils.isNotEmpty("xx "), is(true));
701 
702         assertThat(StringUtils.isNotEmpty("  "), is(true));
703 
704         assertThat(StringUtils.isNotEmpty(""), is(false));
705 
706         assertThat(StringUtils.isNotEmpty("  \t "), is(true));
707 
708         assertThat(StringUtils.isNotEmpty("  \n "), is(true));
709     }
710 
711     @Test
712     public void testIsNumeric() {
713         assertThat(StringUtils.isNumeric(null), is(false));
714 
715         assertThat(StringUtils.isNumeric("2"), is(true));
716 
717         assertThat(StringUtils.isNumeric("asvsdfSDF"), is(false));
718 
719         assertThat(StringUtils.isNumeric("asvsdfSDF  "), is(false));
720 
721         assertThat(StringUtils.isNumeric("asvsdfSDF \t "), is(false));
722 
723         assertThat(StringUtils.isNumeric("435afsafd3!"), is(false));
724 
725         assertThat(StringUtils.isNumeric("435afsafd3"), is(false));
726 
727         assertThat(StringUtils.isNumeric("435 "), is(false));
728 
729         assertThat(StringUtils.isNumeric("435"), is(true));
730     }
731 
732     @Test
733     public void testIsWhitespace() {
734         assertThat(StringUtils.isWhitespace(null), is(false));
735 
736         assertThat(StringUtils.isWhitespace("xx"), is(false));
737 
738         assertThat(StringUtils.isWhitespace("xx "), is(false));
739 
740         assertThat(StringUtils.isWhitespace("  "), is(true));
741 
742         assertThat(StringUtils.isWhitespace(""), is(true));
743 
744         assertThat(StringUtils.isWhitespace("  \t "), is(true));
745 
746         assertThat(StringUtils.isWhitespace("  \n "), is(true));
747     }
748 
749     @Test(expected = NullPointerException.class)
750     public void testJoin_Array_NPE() {
751         StringUtils.join((Object[]) null, null);
752     }
753 
754     @Test
755     public void testJoin_Array() {
756         assertThat(StringUtils.join(new Object[0], null), is(""));
757 
758         assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, null), is("abc"));
759 
760         assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, "__"), is("a__b__c"));
761     }
762 
763     @Test(expected = NullPointerException.class)
764     public void testJoin_Iterator_NPE() {
765         StringUtils.join((Iterator<?>) null, null);
766     }
767 
768     @Test
769     public void testJoin_Iterator() {
770         ArrayList<String> list = new ArrayList<String>();
771 
772         assertThat(StringUtils.join(list.iterator(), null), is(""));
773 
774         list.add("a");
775         list.add("b");
776         list.add("c");
777 
778         assertThat(StringUtils.join(list.iterator(), null), is("abc"));
779 
780         assertThat(StringUtils.join(list.iterator(), "__"), is("a__b__c"));
781     }
782 
783     @Test
784     public void testLastIndexOfAny() {
785         assertThat(StringUtils.lastIndexOfAny(null, null), is(-1));
786 
787         assertThat(StringUtils.lastIndexOfAny("dings", null), is(-1));
788 
789         assertThat(StringUtils.lastIndexOfAny("dings bums boms", new String[] {"ms", " b"}), is(13));
790 
791         assertThat(StringUtils.lastIndexOfAny("dings bums boms", new String[] {"nix", "da"}), is(-1));
792     }
793 
794     @Test(expected = IllegalArgumentException.class)
795     public void testLeft_IAE() {
796         StringUtils.left(null, -1);
797     }
798 
799     @Test
800     public void testLeft() {
801         assertThat(StringUtils.left(null, 4), nullValue());
802 
803         assertThat(StringUtils.left("dingsbums", 4), is("ding"));
804 
805         assertThat(StringUtils.left("dingsbums", 40), is("dingsbums"));
806 
807         assertThat(StringUtils.left("dingsbums", 0), is(""));
808     }
809 
810     @Test(expected = NullPointerException.class)
811     public void testLeftPad1_NPE() {
812         StringUtils.leftPad(null, 0);
813     }
814 
815     @Test
816     public void testLeftPad1() {
817         assertThat(StringUtils.leftPad("dings", 0), is("dings"));
818 
819         assertThat(StringUtils.leftPad("dings", 2), is("dings"));
820 
821         assertThat(StringUtils.leftPad("dings", 10), is("     dings"));
822     }
823 
824     @Test(expected = NullPointerException.class)
825     public void testLeftPad2_NPE1() {
826         StringUtils.leftPad(null, 0, null);
827     }
828 
829     @Test(expected = NullPointerException.class)
830     public void testLeftPad2_NPE2() {
831         StringUtils.leftPad("dings", 0, null);
832     }
833 
834     @Test(expected = NullPointerException.class)
835     public void testLeftPad2_NPE3() {
836         StringUtils.leftPad(null, 0, "*");
837     }
838 
839     @Test
840     public void testLeftPad2() {
841         assertThat(StringUtils.leftPad("dings", 0, "*"), is("dings"));
842 
843         assertThat(StringUtils.leftPad("dings", 2, "*"), is("dings"));
844 
845         assertThat(StringUtils.leftPad("dings", 10, "*"), is("*****dings"));
846     }
847 
848     @Test
849     public void testLowerCase() {
850         assertThat(StringUtils.lowerCase(null), nullValue());
851 
852         assertThat(StringUtils.lowerCase("dinGSbuMS"), is("dingsbums"));
853 
854         assertThat(StringUtils.lowerCase(""), is(""));
855     }
856 
857     @Test(expected = NullPointerException.class)
858     public void testLowerCaseFirstLetter_NPE() {
859         StringUtils.lowercaseFirstLetter(null);
860     }
861 
862     @Test
863     public void testLowerCaseFirstLetter() {
864         assertThat(StringUtils.lowercaseFirstLetter("Dings Bums"), is("dings Bums"));
865     }
866 
867     @Test(expected = IllegalArgumentException.class)
868     public void testMid_NegativeLen() {
869         StringUtils.mid(null, 0, -2);
870     }
871 
872     @Test(expected = IndexOutOfBoundsException.class)
873     public void testMid_WrongPos() {
874         StringUtils.mid(null, -2, 3);
875     }
876 
877     @Test
878     public void testMid() {
879         assertThat(StringUtils.mid(null, 0, 0), nullValue());
880 
881         assertThat(StringUtils.mid("dings bums", 0, 0), is(""));
882 
883         assertThat(StringUtils.mid("dings bums", 3, 4), is("gs b"));
884     }
885 
886     @Test(expected = NullPointerException.class)
887     public void testOverlayString_NPE1() {
888         StringUtils.overlayString(null, null, 0, 0);
889     }
890 
891     @Test(expected = NullPointerException.class)
892     public void testOverlayString_NPE2() {
893         StringUtils.overlayString("dings", null, 0, 0);
894     }
895 
896     @Test(expected = NullPointerException.class)
897     public void testOverlayString_NPE3() {
898         StringUtils.overlayString(null, "bums", 0, 0);
899     }
900 
901     @Test
902     public void testOverlayString() {
903         assertThat(StringUtils.overlayString("dings", "bums", 0, 0), is("bumsdings"));
904 
905         assertThat(StringUtils.overlayString("dings", "bums", 2, 4), is("dibumss"));
906     }
907 
908     @Test(expected = NullPointerException.class)
909     public void testPrechomp_NPE1() {
910         StringUtils.prechomp(null, null);
911     }
912 
913     @Test(expected = NullPointerException.class)
914     public void testPrechomp_NPE2() {
915         StringUtils.prechomp("dings", null);
916     }
917 
918     @Test(expected = NullPointerException.class)
919     public void testPrechomp_NPE3() {
920         StringUtils.prechomp(null, "bums");
921     }
922 
923     @Test
924     public void testPrechomp() {
925         assertThat(StringUtils.prechomp("dings bums", " "), is("bums"));
926 
927         assertThat(StringUtils.prechomp("dings bums", "nix"), is("dings bums"));
928     }
929 
930     @Test
931     public void testQuoteAndEscape1() {
932         assertThat(StringUtils.quoteAndEscape(null, '+'), nullValue());
933 
934         assertThat(StringUtils.quoteAndEscape("", '+'), is(""));
935 
936         assertThat(StringUtils.quoteAndEscape("abc", '"'), is("abc"));
937 
938         assertThat(StringUtils.quoteAndEscape("a\"bc", '"'), is("\"a\\\"bc\""));
939 
940         assertThat(StringUtils.quoteAndEscape("a\'bc", '\''), is("\'a\\'bc\'"));
941 
942         assertThat(StringUtils.quoteAndEscape("a\"bc", '\''), is("a\"bc"));
943     }
944 
945     @Test
946     public void testQuoteAndEscape2() {
947         assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}), nullValue());
948 
949         assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}), is(""));
950 
951         assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}), is("abc"));
952 
953         assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}), is("\"a\\\"bc\""));
954 
955         assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}), is("\'a\\'bc\'"));
956 
957         assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}), is("a\"bc"));
958 
959         assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}), is("\'a\"bc\'"));
960     }
961 
962     @Test
963     public void testQuoteAndEscape3() {
964         assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', false), nullValue());
965 
966         assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', false), is(""));
967 
968         assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', false), is("abc"));
969 
970         assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', false), is("\"a\\\"bc\""));
971 
972         assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, '\\', false), is("a\'bc"));
973 
974         assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', false), is("a\"bc"));
975 
976         assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', false), is("\'a\\\"bc\'"));
977 
978         // with force flag
979         assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', true), nullValue());
980 
981         assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', true), is("++"));
982 
983         assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', true), is("\"abc\""));
984 
985         assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', true), is("\"a\\\"bc\""));
986 
987         assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, '\\', true), is("\'a\'bc\'"));
988 
989         assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', true), is("\'a\"bc\'"));
990 
991         assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', true), is("\'a\\\"bc\'"));
992     }
993 
994     @Test
995     public void testQuoteAndEscape4() {
996         assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', false), nullValue());
997 
998         assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', false), is(""));
999 
1000         assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false), is("abc"));
1001 
1002         assertThat(
1003                 StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false),
1004                 is("\"a\\\"bc\""));
1005 
1006         assertThat(
1007                 StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', false),
1008                 is("a\'bc"));
1009 
1010         assertThat(
1011                 StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', false),
1012                 is("\'a\"bc\'"));
1013 
1014         assertThat(
1015                 StringUtils.quoteAndEscape("\'a\"bc\'", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', false),
1016                 is("\'a\"bc\'"));
1017 
1018         // with force flag
1019         assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', true), nullValue());
1020 
1021         assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', true), is("++"));
1022 
1023         assertThat(
1024                 StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true), is("\"abc\""));
1025 
1026         assertThat(
1027                 StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true),
1028                 is("\"a\\\"bc\""));
1029 
1030         assertThat(
1031                 StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', true),
1032                 is("\'a\'bc\'"));
1033 
1034         assertThat(
1035                 StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', true),
1036                 is("\'a\"bc\'"));
1037 
1038         assertThat(
1039                 StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', true),
1040                 is("\'a\\\"bc\'"));
1041     }
1042 
1043     @Test(expected = NullPointerException.class)
1044     public void testRemoveAndHump_NPE1() {
1045         StringUtils.removeAndHump(null, null);
1046     }
1047 
1048     @Test(expected = NullPointerException.class)
1049     public void testRemoveAndHump_NPE2() {
1050         StringUtils.removeAndHump("dings", null);
1051     }
1052 
1053     @Test(expected = NullPointerException.class)
1054     public void testRemoveAndHump_NPE3() {
1055         StringUtils.removeAndHump(null, "bums");
1056     }
1057 
1058     @Test
1059     public void testRemoveAndHump() {
1060         assertThat(StringUtils.removeAndHump("dings", "bums"), is("Ding"));
1061 
1062         assertThat(StringUtils.removeAndHump("this-is-it", "-"), is("ThisIsIt"));
1063 
1064         assertThat(StringUtils.removeAndHump("THIS-IS-IT", "-"), is("THISISIT"));
1065     }
1066 
1067     @Test(expected = NullPointerException.class)
1068     public void testRemoveDuplicateWhitespace_NPE() {
1069         StringUtils.removeDuplicateWhitespace(null);
1070     }
1071 
1072     @Test
1073     public void testRemoveDuplicateWhitespace() {
1074         assertThat(StringUtils.removeDuplicateWhitespace("dings"), is("dings"));
1075 
1076         assertThat(StringUtils.removeDuplicateWhitespace("dings bums"), is("dings bums"));
1077 
1078         assertThat(StringUtils.removeDuplicateWhitespace("dings  bums"), is("dings bums"));
1079 
1080         assertThat(StringUtils.removeDuplicateWhitespace("dings \t bums"), is("dings bums"));
1081     }
1082 
1083     @Test(expected = NullPointerException.class)
1084     public void testRepeat_NPE() {
1085         StringUtils.repeat(null, 0);
1086     }
1087 
1088     @Test(expected = NegativeArraySizeException.class)
1089     public void testRepeat_NegativeAmount() {
1090         StringUtils.repeat("dings", -1);
1091     }
1092 
1093     @Test
1094     public void testRepeat() {
1095         assertThat(StringUtils.repeat("dings", 0), is(""));
1096 
1097         assertThat(StringUtils.repeat("dings", 1), is("dings"));
1098 
1099         assertThat(StringUtils.repeat("dings", 3), is("dingsdingsdings"));
1100     }
1101 
1102     @Test
1103     public void testReplace_char() {
1104         assertThat(StringUtils.replace(null, 'i', 'o'), nullValue());
1105 
1106         assertThat(StringUtils.replace("dings", 'i', 'o'), is("dongs"));
1107 
1108         assertThat(StringUtils.replace("dingsbims", 'i', 'o'), is("dongsboms"));
1109 
1110         assertThat(StringUtils.replace("dings", 'x', 'o'), is("dings"));
1111     }
1112 
1113     @Test
1114     public void testReplace2_char_max() {
1115         assertThat(StringUtils.replace(null, 'i', 'o', 0), nullValue());
1116 
1117         assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 3), is("dongsobumso"));
1118 
1119         assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 2), is("dongsobumsi"));
1120 
1121         assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 0), is("dongsobumso"));
1122 
1123         assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', -2), is("dongsobumso"));
1124 
1125         assertThat(StringUtils.replace("dings", 'x', 'o', 2), is("dings"));
1126     }
1127 
1128     @Test
1129     public void testReplace_string() {
1130         assertThat(StringUtils.replace(null, "in", "ox"), nullValue());
1131 
1132         assertThat(StringUtils.replace("dings", "in", "ox"), is("doxgs"));
1133 
1134         assertThat(StringUtils.replace("dingsbins", "in", "ox"), is("doxgsboxs"));
1135 
1136         assertThat(StringUtils.replace("dings", "nin", "ox"), is("dings"));
1137     }
1138 
1139     @Test
1140     public void testReplace2_string_max() {
1141         assertThat(StringUtils.replace(null, "in", "ox", 0), nullValue());
1142 
1143         assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 3), is("dingxobumxo"));
1144 
1145         assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 2), is("dingxobumxo"));
1146 
1147         assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 1), is("dingxobumsi"));
1148 
1149         assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 0), is("dingxobumxo"));
1150 
1151         assertThat(StringUtils.replace("dingsibumsi", "si", "xo", -2), is("dingxobumxo"));
1152 
1153         assertThat(StringUtils.replace("dings", "si", "xo", 2), is("dings"));
1154     }
1155 
1156     @Test
1157     public void testReplaceOnce_char() {
1158         assertThat(StringUtils.replaceOnce(null, 'i', 'o'), nullValue());
1159 
1160         assertThat(StringUtils.replaceOnce("dingsibumsi", 'i', 'o'), is("dongsibumsi"));
1161 
1162         assertThat(StringUtils.replaceOnce("dings", 'x', 'o'), is("dings"));
1163     }
1164 
1165     @Test
1166     public void testReplaceOnce_string() {
1167         assertThat(StringUtils.replaceOnce(null, "in", "ox"), nullValue());
1168 
1169         assertThat(StringUtils.replaceOnce("dingsibumsi", "si", "xo"), is("dingxobumsi"));
1170 
1171         assertThat(StringUtils.replaceOnce("dings", "si", "xo"), is("dings"));
1172     }
1173 
1174     @Test
1175     public void testReverse() {
1176         assertThat(StringUtils.reverse(null), nullValue());
1177 
1178         assertThat(StringUtils.reverse(""), is(""));
1179 
1180         assertThat(StringUtils.reverse("dings"), is("sgnid"));
1181 
1182         assertThat(StringUtils.reverse("  dings "), is(" sgnid  "));
1183     }
1184 
1185     @Test(expected = NullPointerException.class)
1186     public void testReverseDelimitedString_NPE1() {
1187         StringUtils.reverseDelimitedString(null, null);
1188     }
1189 
1190     @Test(expected = NullPointerException.class)
1191     public void testReverseDelimitedString_NPE2() {
1192         StringUtils.reverseDelimitedString(null, " ");
1193     }
1194 
1195     @Test
1196     public void testReverseDelimitedString() {
1197         assertThat(StringUtils.reverseDelimitedString("dings", null), is("dings"));
1198 
1199         assertThat(StringUtils.reverseDelimitedString("", " "), is(""));
1200 
1201         assertThat(StringUtils.reverseDelimitedString("dings", " "), is("dings"));
1202 
1203         assertThat(StringUtils.reverseDelimitedString("  dings ", " "), is("dings"));
1204 
1205         assertThat(StringUtils.reverseDelimitedString("dings bums", " "), is("bums dings"));
1206     }
1207 
1208     @Test(expected = IllegalArgumentException.class)
1209     public void testRight_IAE1() {
1210         StringUtils.right(null, -1);
1211     }
1212 
1213     @Test(expected = IllegalArgumentException.class)
1214     public void testRight_IAE2() {
1215         StringUtils.right("dings", -1);
1216     }
1217 
1218     @Test
1219     public void testRight() {
1220         assertThat(StringUtils.right(null, 0), nullValue());
1221 
1222         assertThat(StringUtils.right("dings", 0), is(""));
1223 
1224         assertThat(StringUtils.right("dings", 3), is("ngs"));
1225 
1226         assertThat(StringUtils.right("dings ", 3), is("gs "));
1227     }
1228 
1229     @Test(expected = NullPointerException.class)
1230     public void testRightPad1_NPE() {
1231         StringUtils.rightPad(null, 0);
1232     }
1233 
1234     @Test
1235     public void testRightPad1() {
1236         assertThat(StringUtils.rightPad("dings", 0), is("dings"));
1237 
1238         assertThat(StringUtils.rightPad("dings", 3), is("dings"));
1239 
1240         assertThat(StringUtils.rightPad("dings", 10), is("dings     "));
1241     }
1242 
1243     @Test(expected = NullPointerException.class)
1244     public void testRightPad2_NPE1() {
1245         StringUtils.rightPad(null, 0, null);
1246     }
1247 
1248     @Test(expected = NullPointerException.class)
1249     public void testRightPad2_NPE2() {
1250         StringUtils.rightPad("dings", 0, null);
1251     }
1252 
1253     @Test(expected = NullPointerException.class)
1254     public void testRightPad2_NPE23() {
1255         StringUtils.rightPad(null, 0, "+");
1256     }
1257 
1258     @Test
1259     public void testRightPad2() {
1260         assertThat(StringUtils.rightPad("dings", 0, "+"), is("dings"));
1261 
1262         assertThat(StringUtils.rightPad("dings", 3, "+"), is("dings"));
1263 
1264         assertThat(StringUtils.rightPad("dings", 10, "+"), is("dings+++++"));
1265     }
1266 
1267     @Test(expected = NullPointerException.class)
1268     public void testSplit1_NPE() {
1269         StringUtils.split(null);
1270     }
1271 
1272     @Test
1273     public void testSplit1() {
1274         assertThat(StringUtils.split("dings"), is(new String[] {"dings"}));
1275 
1276         assertThat(StringUtils.split("dings bums"), is(new String[] {"dings", "bums"}));
1277     }
1278 
1279     @Test(expected = NullPointerException.class)
1280     public void testSplit2_NPE1() {
1281         StringUtils.split(null, null);
1282     }
1283 
1284     @Test(expected = NullPointerException.class)
1285     public void testSplit2_NPE2() {
1286         StringUtils.split(null, " ");
1287     }
1288 
1289     @Test
1290     public void testSplit2() {
1291         assertThat(StringUtils.split("dings", null), is(new String[] {"dings"}));
1292 
1293         assertThat(StringUtils.split("dings bums", null), is(new String[] {"dings", "bums"}));
1294 
1295         assertThat(StringUtils.split("dings", "+"), is(new String[] {"dings"}));
1296 
1297         assertThat(StringUtils.split("dings+bums", "+"), is(new String[] {"dings", "bums"}));
1298     }
1299 
1300     @Test(expected = NullPointerException.class)
1301     public void testSplit3_NPE1() {
1302         StringUtils.split(null, null, 1);
1303     }
1304 
1305     @Test(expected = NullPointerException.class)
1306     public void testSplit3_NPE2() {
1307         StringUtils.split(null, " ", 1);
1308     }
1309 
1310     @Test
1311     public void testSplit3() {
1312         assertThat(StringUtils.split("dings", null, 3), is(new String[] {"dings"}));
1313 
1314         assertThat(StringUtils.split("dings bums", null, 3), is(new String[] {"dings", "bums"}));
1315 
1316         assertThat(StringUtils.split("dings", "+", 3), is(new String[] {"dings"}));
1317 
1318         assertThat(StringUtils.split("dings+bums", "+", 3), is(new String[] {"dings", "bums"}));
1319 
1320         assertThat(StringUtils.split("dings+bums", "+", 1), is(new String[] {"dings+bums"}));
1321 
1322         assertThat(StringUtils.split("dings+bums", "+", 0), is(new String[] {"dings", "bums"}));
1323 
1324         assertThat(StringUtils.split("dings+bums", "+", -5), is(new String[] {"dings", "bums"}));
1325     }
1326 
1327     @Test
1328     public void testStrip1() {
1329         assertThat(StringUtils.strip(null), nullValue());
1330 
1331         assertThat(StringUtils.strip("dings"), is("dings"));
1332 
1333         assertThat(StringUtils.strip("  dings \t "), is("dings"));
1334     }
1335 
1336     @Test
1337     public void testStrip2() {
1338         assertThat(StringUtils.strip(null, " "), nullValue());
1339 
1340         assertThat(StringUtils.strip(null, null), nullValue());
1341 
1342         assertThat(StringUtils.strip("dings", " "), is("dings"));
1343 
1344         assertThat(StringUtils.strip("  dings \t ", " "), is("dings \t"));
1345     }
1346 
1347     @Test
1348     public void testStripAll1() {
1349         assertThat(StringUtils.stripAll(null), nullValue());
1350 
1351         assertThat(StringUtils.stripAll(new String[] {}), is(new String[] {}));
1352 
1353         assertThat(StringUtils.stripAll(new String[] {"dings"}), is(new String[] {"dings"}));
1354 
1355         assertThat(StringUtils.stripAll(new String[] {" dings ", "  bums \t  "}), is(new String[] {"dings", "bums"}));
1356     }
1357 
1358     @Test
1359     public void testStripAll2() {
1360         assertThat(StringUtils.stripAll(null, " "), nullValue());
1361 
1362         assertThat(StringUtils.stripAll(new String[] {}, " "), is(new String[] {}));
1363 
1364         assertThat(StringUtils.stripAll(new String[] {"dings"}, " "), is(new String[] {"dings"}));
1365 
1366         assertThat(
1367                 StringUtils.stripAll(new String[] {" dings ", "  bums \t  "}, " "),
1368                 is(new String[] {"dings", "bums \t"}));
1369     }
1370 
1371     @Test
1372     public void testStripEnd() {
1373         assertThat(StringUtils.stripEnd(null, null), nullValue());
1374 
1375         assertThat(StringUtils.stripEnd("dings", null), is("dings"));
1376 
1377         assertThat(StringUtils.stripEnd("  dings \t ", null), is("  dings"));
1378 
1379         assertThat(StringUtils.stripEnd(null, " "), nullValue());
1380 
1381         assertThat(StringUtils.stripEnd("dings", " "), is("dings"));
1382 
1383         assertThat(StringUtils.stripEnd("  dings \t ", " "), is("  dings \t"));
1384     }
1385 
1386     @Test
1387     public void testStripStart() {
1388         assertThat(StringUtils.stripStart(null, null), nullValue());
1389 
1390         assertThat(StringUtils.stripStart("dings", null), is("dings"));
1391 
1392         assertThat(StringUtils.stripStart("  dings \t ", null), is("dings \t "));
1393 
1394         assertThat(StringUtils.stripStart(null, " "), nullValue());
1395 
1396         assertThat(StringUtils.stripStart("dings", " "), is("dings"));
1397 
1398         assertThat(StringUtils.stripStart("  \t dings \t ", " "), is("\t dings \t "));
1399     }
1400 
1401     @Test
1402     public void testSubstring1() {
1403         assertThat(StringUtils.substring(null, 0), nullValue());
1404         assertThat(StringUtils.substring(null, -3), nullValue());
1405 
1406         assertThat(StringUtils.substring("dings", 2), is("ngs"));
1407 
1408         assertThat(StringUtils.substring("dings", -2), is("gs"));
1409 
1410         assertThat(StringUtils.substring("dings", 20), is(""));
1411     }
1412 
1413     @Test
1414     public void testSubstring2() {
1415         assertThat(StringUtils.substring(null, 0, 2), nullValue());
1416 
1417         assertThat(StringUtils.substring(null, -3, 0), nullValue());
1418 
1419         assertThat(StringUtils.substring("dings", 2, 4), is("ng"));
1420 
1421         assertThat(StringUtils.substring("dings", -2, 4), is("g"));
1422 
1423         assertThat(StringUtils.substring("dings", 20, 23), is(""));
1424 
1425         assertThat(StringUtils.substring("dings", 4, 2), is(""));
1426     }
1427 
1428     @Test
1429     public void testSwapCase() {
1430         assertThat(StringUtils.swapCase(null), nullValue());
1431 
1432         assertThat(StringUtils.swapCase("dings"), is("DINGS"));
1433 
1434         assertThat(StringUtils.swapCase("DinGs"), is("dINgS"));
1435     }
1436 
1437     @Test
1438     public void testTrim() {
1439         assertThat(StringUtils.trim(null), nullValue());
1440 
1441         assertThat(StringUtils.trim("   "), is(""));
1442 
1443         assertThat(StringUtils.trim("  c "), is("c"));
1444 
1445         assertThat(StringUtils.trim("  dings \n  "), is("dings"));
1446     }
1447 
1448     @Test
1449     public void testUncapitalise() {
1450         assertThat(StringUtils.uncapitalise(null), nullValue());
1451 
1452         assertThat(StringUtils.uncapitalise("   "), is("   "));
1453 
1454         assertThat(StringUtils.uncapitalise("dings"), is("dings"));
1455 
1456         assertThat(StringUtils.uncapitalise("Dings"), is("dings"));
1457 
1458         assertThat(StringUtils.uncapitalise("DINGS"), is("dINGS"));
1459     }
1460 
1461     @Test
1462     public void testUncapitaliseAllWords() {
1463         assertThat(StringUtils.uncapitaliseAllWords(null), nullValue());
1464 
1465         assertThat(StringUtils.uncapitaliseAllWords("   "), is("   "));
1466 
1467         assertThat(StringUtils.uncapitaliseAllWords("dings bums"), is("dings bums"));
1468 
1469         assertThat(StringUtils.uncapitaliseAllWords("Dings Bums"), is("dings bums"));
1470 
1471         assertThat(StringUtils.uncapitaliseAllWords("DINGS Bums"), is("dINGS bums"));
1472     }
1473 
1474     @Test
1475     public void testUnifyLineSeparators1() {
1476         String sls = System.getProperty("line.separator");
1477 
1478         assertThat(StringUtils.unifyLineSeparators(null), nullValue());
1479 
1480         assertThat(StringUtils.unifyLineSeparators("   "), is("   "));
1481 
1482         assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs"), is("dings" + sls + "bums" + sls + "dongs"));
1483     }
1484 
1485     @Test
1486     public void testUnifyLineSeparators2() {
1487         assertThat(StringUtils.unifyLineSeparators(null, "\n"), nullValue());
1488 
1489         assertThat(StringUtils.unifyLineSeparators("   ", "\n"), is("   "));
1490 
1491         assertThat(
1492                 StringUtils.unifyLineSeparators("   ", null) // takes the sytem line separator
1493                 ,
1494                 is("   "));
1495 
1496         assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs", "\n"), is("dings\nbums\ndongs"));
1497     }
1498 
1499     @Test
1500     public void testUppercase() {
1501         assertThat(StringUtils.upperCase(null), nullValue());
1502 
1503         assertThat(StringUtils.upperCase("   "), is("   "));
1504 
1505         assertThat(StringUtils.upperCase(""), is(""));
1506 
1507         assertThat(StringUtils.upperCase("dings"), is("DINGS"));
1508     }
1509 }