32
32
public class StringUtilsTests {
33
33
34
34
@ Test
35
- public void testHasTextBlank () throws Exception {
35
+ public void testHasTextBlank () {
36
36
String blank = " " ;
37
37
assertEquals (false , StringUtils .hasText (blank ));
38
38
}
39
39
40
40
@ Test
41
- public void testHasTextNullEmpty () throws Exception {
41
+ public void testHasTextNullEmpty () {
42
42
assertEquals (false , StringUtils .hasText (null ));
43
43
assertEquals (false , StringUtils .hasText ("" ));
44
44
}
45
45
46
46
@ Test
47
- public void testHasTextValid () throws Exception {
47
+ public void testHasTextValid () {
48
48
assertEquals (true , StringUtils .hasText ("t" ));
49
49
}
50
50
51
51
@ Test
52
- public void testContainsWhitespace () throws Exception {
52
+ public void testContainsWhitespace () {
53
53
assertFalse (StringUtils .containsWhitespace (null ));
54
54
assertFalse (StringUtils .containsWhitespace ("" ));
55
55
assertFalse (StringUtils .containsWhitespace ("a" ));
@@ -62,7 +62,7 @@ public void testContainsWhitespace() throws Exception {
62
62
}
63
63
64
64
@ Test
65
- public void testTrimWhitespace () throws Exception {
65
+ public void testTrimWhitespace () {
66
66
assertEquals (null , StringUtils .trimWhitespace (null ));
67
67
assertEquals ("" , StringUtils .trimWhitespace ("" ));
68
68
assertEquals ("" , StringUtils .trimWhitespace (" " ));
@@ -75,7 +75,7 @@ public void testTrimWhitespace() throws Exception {
75
75
}
76
76
77
77
@ Test
78
- public void testTrimAllWhitespace () throws Exception {
78
+ public void testTrimAllWhitespace () {
79
79
assertEquals ("" , StringUtils .trimAllWhitespace ("" ));
80
80
assertEquals ("" , StringUtils .trimAllWhitespace (" " ));
81
81
assertEquals ("" , StringUtils .trimAllWhitespace ("\t " ));
@@ -87,7 +87,7 @@ public void testTrimAllWhitespace() throws Exception {
87
87
}
88
88
89
89
@ Test
90
- public void testTrimLeadingWhitespace () throws Exception {
90
+ public void testTrimLeadingWhitespace () {
91
91
assertEquals (null , StringUtils .trimLeadingWhitespace (null ));
92
92
assertEquals ("" , StringUtils .trimLeadingWhitespace ("" ));
93
93
assertEquals ("" , StringUtils .trimLeadingWhitespace (" " ));
@@ -100,7 +100,7 @@ public void testTrimLeadingWhitespace() throws Exception {
100
100
}
101
101
102
102
@ Test
103
- public void testTrimTrailingWhitespace () throws Exception {
103
+ public void testTrimTrailingWhitespace () {
104
104
assertEquals (null , StringUtils .trimTrailingWhitespace (null ));
105
105
assertEquals ("" , StringUtils .trimTrailingWhitespace ("" ));
106
106
assertEquals ("" , StringUtils .trimTrailingWhitespace (" " ));
@@ -113,7 +113,7 @@ public void testTrimTrailingWhitespace() throws Exception {
113
113
}
114
114
115
115
@ Test
116
- public void testTrimLeadingCharacter () throws Exception {
116
+ public void testTrimLeadingCharacter () {
117
117
assertEquals (null , StringUtils .trimLeadingCharacter (null , ' ' ));
118
118
assertEquals ("" , StringUtils .trimLeadingCharacter ("" , ' ' ));
119
119
assertEquals ("" , StringUtils .trimLeadingCharacter (" " , ' ' ));
@@ -126,7 +126,7 @@ public void testTrimLeadingCharacter() throws Exception {
126
126
}
127
127
128
128
@ Test
129
- public void testTrimTrailingCharacter () throws Exception {
129
+ public void testTrimTrailingCharacter () {
130
130
assertEquals (null , StringUtils .trimTrailingCharacter (null , ' ' ));
131
131
assertEquals ("" , StringUtils .trimTrailingCharacter ("" , ' ' ));
132
132
assertEquals ("" , StringUtils .trimTrailingCharacter (" " , ' ' ));
@@ -138,6 +138,60 @@ public void testTrimTrailingCharacter() throws Exception {
138
138
assertEquals (" a b c" , StringUtils .trimTrailingCharacter (" a b c " , ' ' ));
139
139
}
140
140
141
+ @ Test
142
+ public void testStartsWithIgnoreCase () {
143
+ String prefix = "fOo" ;
144
+ assertTrue (StringUtils .startsWithIgnoreCase ("foo" , prefix ));
145
+ assertTrue (StringUtils .startsWithIgnoreCase ("Foo" , prefix ));
146
+ assertTrue (StringUtils .startsWithIgnoreCase ("foobar" , prefix ));
147
+ assertTrue (StringUtils .startsWithIgnoreCase ("foobarbar" , prefix ));
148
+ assertTrue (StringUtils .startsWithIgnoreCase ("Foobar" , prefix ));
149
+ assertTrue (StringUtils .startsWithIgnoreCase ("FoobarBar" , prefix ));
150
+ assertTrue (StringUtils .startsWithIgnoreCase ("foObar" , prefix ));
151
+ assertTrue (StringUtils .startsWithIgnoreCase ("FOObar" , prefix ));
152
+ assertTrue (StringUtils .startsWithIgnoreCase ("fOobar" , prefix ));
153
+ assertFalse (StringUtils .startsWithIgnoreCase (null , prefix ));
154
+ assertFalse (StringUtils .startsWithIgnoreCase ("fOobar" , null ));
155
+ assertFalse (StringUtils .startsWithIgnoreCase ("b" , prefix ));
156
+ assertFalse (StringUtils .startsWithIgnoreCase ("barfoo" , prefix ));
157
+ assertFalse (StringUtils .startsWithIgnoreCase ("barfoobar" , prefix ));
158
+ }
159
+
160
+ @ Test
161
+ public void testEndsWithIgnoreCase () {
162
+ String suffix = "fOo" ;
163
+ assertTrue (StringUtils .endsWithIgnoreCase ("foo" , suffix ));
164
+ assertTrue (StringUtils .endsWithIgnoreCase ("Foo" , suffix ));
165
+ assertTrue (StringUtils .endsWithIgnoreCase ("barfoo" , suffix ));
166
+ assertTrue (StringUtils .endsWithIgnoreCase ("barbarfoo" , suffix ));
167
+ assertTrue (StringUtils .endsWithIgnoreCase ("barFoo" , suffix ));
168
+ assertTrue (StringUtils .endsWithIgnoreCase ("barBarFoo" , suffix ));
169
+ assertTrue (StringUtils .endsWithIgnoreCase ("barfoO" , suffix ));
170
+ assertTrue (StringUtils .endsWithIgnoreCase ("barFOO" , suffix ));
171
+ assertTrue (StringUtils .endsWithIgnoreCase ("barfOo" , suffix ));
172
+ assertFalse (StringUtils .endsWithIgnoreCase (null , suffix ));
173
+ assertFalse (StringUtils .endsWithIgnoreCase ("barfOo" , null ));
174
+ assertFalse (StringUtils .endsWithIgnoreCase ("b" , suffix ));
175
+ assertFalse (StringUtils .endsWithIgnoreCase ("foobar" , suffix ));
176
+ assertFalse (StringUtils .endsWithIgnoreCase ("barfoobar" , suffix ));
177
+ }
178
+
179
+ @ Test
180
+ public void testSubstringMatch () {
181
+ assertTrue (StringUtils .substringMatch ("foo" , 0 , "foo" ));
182
+ assertTrue (StringUtils .substringMatch ("foo" , 1 , "oo" ));
183
+ assertTrue (StringUtils .substringMatch ("foo" , 2 , "o" ));
184
+ assertFalse (StringUtils .substringMatch ("foo" , 0 , "fOo" ));
185
+ assertFalse (StringUtils .substringMatch ("foo" , 1 , "fOo" ));
186
+ assertFalse (StringUtils .substringMatch ("foo" , 2 , "fOo" ));
187
+ assertFalse (StringUtils .substringMatch ("foo" , 3 , "fOo" ));
188
+ assertFalse (StringUtils .substringMatch ("foo" , 1 , "Oo" ));
189
+ assertFalse (StringUtils .substringMatch ("foo" , 2 , "Oo" ));
190
+ assertFalse (StringUtils .substringMatch ("foo" , 3 , "Oo" ));
191
+ assertFalse (StringUtils .substringMatch ("foo" , 2 , "O" ));
192
+ assertFalse (StringUtils .substringMatch ("foo" , 3 , "O" ));
193
+ }
194
+
141
195
@ Test
142
196
public void testCountOccurrencesOf () {
143
197
assertTrue ("nullx2 = 0" ,
@@ -166,7 +220,7 @@ public void testCountOccurrencesOf() {
166
220
}
167
221
168
222
@ Test
169
- public void testReplace () throws Exception {
223
+ public void testReplace () {
170
224
String inString = "a6AazAaa77abaa" ;
171
225
String oldPattern = "aa" ;
172
226
String newPattern = "foo" ;
@@ -189,7 +243,7 @@ public void testReplace() throws Exception {
189
243
}
190
244
191
245
@ Test
192
- public void testDelete () throws Exception {
246
+ public void testDelete () {
193
247
String inString = "The quick brown fox jumped over the lazy dog" ;
194
248
195
249
String noThe = StringUtils .delete (inString , "the" );
@@ -216,7 +270,7 @@ public void testDelete() throws Exception {
216
270
}
217
271
218
272
@ Test
219
- public void testDeleteAny () throws Exception {
273
+ public void testDeleteAny () {
220
274
String inString = "Able was I ere I saw Elba" ;
221
275
222
276
String res = StringUtils .deleteAny (inString , "I" );
@@ -301,7 +355,6 @@ public void testGetFilenameExtension() {
301
355
302
356
@ Test
303
357
public void testStripFilenameExtension () {
304
- assertEquals (null , StringUtils .stripFilenameExtension (null ));
305
358
assertEquals ("" , StringUtils .stripFilenameExtension ("" ));
306
359
assertEquals ("myfile" , StringUtils .stripFilenameExtension ("myfile" ));
307
360
assertEquals ("myfile" , StringUtils .stripFilenameExtension ("myfile." ));
@@ -580,86 +633,69 @@ private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components
580
633
assertTrue ("Output equals input" , Arrays .equals (sa , components ));
581
634
}
582
635
583
- @ Test
584
- public void testEndsWithIgnoreCase () {
585
- String suffix = "fOo" ;
586
- assertTrue (StringUtils .endsWithIgnoreCase ("foo" , suffix ));
587
- assertTrue (StringUtils .endsWithIgnoreCase ("Foo" , suffix ));
588
- assertTrue (StringUtils .endsWithIgnoreCase ("barfoo" , suffix ));
589
- assertTrue (StringUtils .endsWithIgnoreCase ("barbarfoo" , suffix ));
590
- assertTrue (StringUtils .endsWithIgnoreCase ("barFoo" , suffix ));
591
- assertTrue (StringUtils .endsWithIgnoreCase ("barBarFoo" , suffix ));
592
- assertTrue (StringUtils .endsWithIgnoreCase ("barfoO" , suffix ));
593
- assertTrue (StringUtils .endsWithIgnoreCase ("barFOO" , suffix ));
594
- assertTrue (StringUtils .endsWithIgnoreCase ("barfOo" , suffix ));
595
- assertFalse (StringUtils .endsWithIgnoreCase (null , suffix ));
596
- assertFalse (StringUtils .endsWithIgnoreCase ("barfOo" , null ));
597
- assertFalse (StringUtils .endsWithIgnoreCase ("b" , suffix ));
598
- }
599
-
600
636
601
637
@ Test
602
- public void testParseLocaleStringSunnyDay () throws Exception {
638
+ public void testParseLocaleStringSunnyDay () {
603
639
Locale expectedLocale = Locale .UK ;
604
640
Locale locale = StringUtils .parseLocaleString (expectedLocale .toString ());
605
641
assertNotNull ("When given a bona-fide Locale string, must not return null." , locale );
606
642
assertEquals (expectedLocale , locale );
607
643
}
608
644
609
645
@ Test
610
- public void testParseLocaleStringWithMalformedLocaleString () throws Exception {
646
+ public void testParseLocaleStringWithMalformedLocaleString () {
611
647
Locale locale = StringUtils .parseLocaleString ("_banjo_on_my_knee" );
612
648
assertNotNull ("When given a malformed Locale string, must not return null." , locale );
613
649
}
614
650
615
651
@ Test
616
- public void testParseLocaleStringWithEmptyLocaleStringYieldsNullLocale () throws Exception {
652
+ public void testParseLocaleStringWithEmptyLocaleStringYieldsNullLocale () {
617
653
Locale locale = StringUtils .parseLocaleString ("" );
618
654
assertNull ("When given an empty Locale string, must return null." , locale );
619
655
}
620
656
621
657
@ Test // SPR-8637
622
- public void testParseLocaleWithMultiSpecialCharactersInVariant () throws Exception {
658
+ public void testParseLocaleWithMultiSpecialCharactersInVariant () {
623
659
String variant = "proper-northern" ;
624
660
String localeString = "en_GB_" + variant ;
625
661
Locale locale = StringUtils .parseLocaleString (localeString );
626
662
assertEquals ("Multi-valued variant portion of the Locale not extracted correctly." , variant , locale .getVariant ());
627
663
}
628
664
629
665
@ Test // SPR-3671
630
- public void testParseLocaleWithMultiValuedVariant () throws Exception {
666
+ public void testParseLocaleWithMultiValuedVariant () {
631
667
String variant = "proper_northern" ;
632
668
String localeString = "en_GB_" + variant ;
633
669
Locale locale = StringUtils .parseLocaleString (localeString );
634
670
assertEquals ("Multi-valued variant portion of the Locale not extracted correctly." , variant , locale .getVariant ());
635
671
}
636
672
637
673
@ Test // SPR-3671
638
- public void testParseLocaleWithMultiValuedVariantUsingSpacesAsSeparators () throws Exception {
674
+ public void testParseLocaleWithMultiValuedVariantUsingSpacesAsSeparators () {
639
675
String variant = "proper northern" ;
640
676
String localeString = "en GB " + variant ;
641
677
Locale locale = StringUtils .parseLocaleString (localeString );
642
678
assertEquals ("Multi-valued variant portion of the Locale not extracted correctly." , variant , locale .getVariant ());
643
679
}
644
680
645
681
@ Test // SPR-3671
646
- public void testParseLocaleWithMultiValuedVariantUsingMixtureOfUnderscoresAndSpacesAsSeparators () throws Exception {
682
+ public void testParseLocaleWithMultiValuedVariantUsingMixtureOfUnderscoresAndSpacesAsSeparators () {
647
683
String variant = "proper northern" ;
648
684
String localeString = "en_GB_" + variant ;
649
685
Locale locale = StringUtils .parseLocaleString (localeString );
650
686
assertEquals ("Multi-valued variant portion of the Locale not extracted correctly." , variant , locale .getVariant ());
651
687
}
652
688
653
689
@ Test // SPR-3671
654
- public void testParseLocaleWithMultiValuedVariantUsingSpacesAsSeparatorsWithLotsOfLeadingWhitespace () throws Exception {
690
+ public void testParseLocaleWithMultiValuedVariantUsingSpacesAsSeparatorsWithLotsOfLeadingWhitespace () {
655
691
String variant = "proper northern" ;
656
692
String localeString = "en GB " + variant ; // lots of whitespace
657
693
Locale locale = StringUtils .parseLocaleString (localeString );
658
694
assertEquals ("Multi-valued variant portion of the Locale not extracted correctly." , variant , locale .getVariant ());
659
695
}
660
696
661
697
@ Test // SPR-3671
662
- public void testParseLocaleWithMultiValuedVariantUsingUnderscoresAsSeparatorsWithLotsOfLeadingWhitespace () throws Exception {
698
+ public void testParseLocaleWithMultiValuedVariantUsingUnderscoresAsSeparatorsWithLotsOfLeadingWhitespace () {
663
699
String variant = "proper_northern" ;
664
700
String localeString = "en_GB_____" + variant ; // lots of underscores
665
701
Locale locale = StringUtils .parseLocaleString (localeString );
0 commit comments