22
33import org .junit .jupiter .api .Test ;
44
5+ import static io .microsphere .collection .ListUtils .newLinkedList ;
6+ import static io .microsphere .collection .Lists .ofList ;
57import static io .microsphere .constants .SymbolConstants .COMMA ;
68import static io .microsphere .constants .SymbolConstants .DOT ;
9+ import static io .microsphere .constants .SymbolConstants .SHARP ;
710import static io .microsphere .constants .SymbolConstants .SPACE ;
811import static io .microsphere .constants .SymbolConstants .VERTICAL_BAR ;
912import static io .microsphere .util .ArrayUtils .ofArray ;
3033import static io .microsphere .util .StringUtils .substringBefore ;
3134import static io .microsphere .util .StringUtils .substringBeforeLast ;
3235import static io .microsphere .util .StringUtils .substringBetween ;
36+ import static io .microsphere .util .StringUtils .toStringArray ;
3337import static io .microsphere .util .StringUtils .trimAllWhitespace ;
3438import static io .microsphere .util .StringUtils .trimLeadingWhitespace ;
3539import static io .microsphere .util .StringUtils .trimTrailingWhitespace ;
3640import static io .microsphere .util .StringUtils .trimWhitespace ;
3741import static io .microsphere .util .StringUtils .uncapitalize ;
42+ import static java .util .Collections .emptyList ;
3843import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
3944import static org .junit .jupiter .api .Assertions .assertEquals ;
4045import static org .junit .jupiter .api .Assertions .assertFalse ;
@@ -172,6 +177,10 @@ void testEndsWith() {
172177 @ Test
173178 void testReplace () {
174179 assertNull (replace (null , null , null ));
180+ assertEquals (TEST_EMPTY_STRING , replace (TEST_EMPTY_STRING , null , null ));
181+ assertEquals (TEST_EMPTY_STRING , replace (TEST_EMPTY_STRING , "null" , null ));
182+ assertEquals (TEST_CSV_STRING , replace (TEST_CSV_STRING , "null" , "null" ));
183+
175184 assertEquals (TEST_EMPTY_STRING , replace (TEST_EMPTY_STRING , null , null ));
176185 assertEquals (TEST_EMPTY_STRING , replace (TEST_EMPTY_STRING , TEST_EMPTY_STRING , null ));
177186 assertEquals (TEST_EMPTY_STRING , replace (TEST_EMPTY_STRING , TEST_EMPTY_STRING , TEST_EMPTY_STRING , 0 ));
@@ -184,6 +193,9 @@ void testReplace() {
184193 assertEquals ("a|b|c" , replace (TEST_CSV_STRING , COMMA , VERTICAL_BAR ));
185194 assertEquals ("a|b|c" , replace (TEST_CSV_STRING , COMMA , VERTICAL_BAR , 100 ));
186195 assertEquals ("a|b,c" , replace (TEST_CSV_STRING , COMMA , VERTICAL_BAR , 1 ));
196+
197+ assertEquals ("abc" , replace (TEST_CSV_STRING , COMMA , EMPTY_STRING ));
198+
187199 }
188200
189201 @ Test
@@ -238,6 +250,7 @@ void testSubstringBeforeLast() {
238250 assertSame (TEST_EMPTY_STRING , substringBeforeLast (TEST_EMPTY_STRING , null ));
239251 assertSame (TEST_CSV_STRING , substringBeforeLast (TEST_CSV_STRING , null ));
240252 assertSame (TEST_CSV_STRING , substringBeforeLast (TEST_CSV_STRING , TEST_EMPTY_STRING ));
253+ assertSame (TEST_CSV_STRING , substringBeforeLast (TEST_CSV_STRING , SHARP ));
241254
242255 assertEquals ("a,b" , substringBeforeLast (TEST_CSV_STRING , COMMA ));
243256 assertEquals ("a," , substringBeforeLast (TEST_CSV_STRING , "b" ));
@@ -257,6 +270,7 @@ void testSubstringAfterLast() {
257270 assertEquals (",c" , substringAfterLast (TEST_CSV_STRING , "b" ));
258271 assertEquals ("c" , substringAfterLast (TEST_CSV_STRING , COMMA ));
259272 assertEquals (TEST_EMPTY_STRING , substringAfterLast (TEST_CSV_STRING , "c" ));
273+ assertEquals (TEST_EMPTY_STRING , substringAfterLast (TEST_CSV_STRING , SHARP ));
260274 }
261275
262276 @ Test
@@ -337,4 +351,12 @@ void testUncapitalize() {
337351 assertSame ("hello world" , uncapitalize ("hello world" ));
338352 }
339353
354+ @ Test
355+ void testToStringArray () {
356+ assertSame (EMPTY_STRING_ARRAY , toStringArray (null ));
357+ assertSame (EMPTY_STRING_ARRAY , toStringArray (emptyList ()));
358+ assertSame (EMPTY_STRING_ARRAY , toStringArray (newLinkedList ()));
359+ assertArrayEquals (ofArray ("a" , "b" , "c" ), toStringArray (ofList ("a" , "b" , "c" )));
360+ }
361+
340362}
0 commit comments