Skip to content

Commit 2b29afd

Browse files
committed
Update StringUtilsTest.java
1 parent 2818838 commit 2b29afd

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import org.junit.jupiter.api.Test;
44

5+
import static io.microsphere.collection.ListUtils.newLinkedList;
6+
import static io.microsphere.collection.Lists.ofList;
57
import static io.microsphere.constants.SymbolConstants.COMMA;
68
import static io.microsphere.constants.SymbolConstants.DOT;
9+
import static io.microsphere.constants.SymbolConstants.SHARP;
710
import static io.microsphere.constants.SymbolConstants.SPACE;
811
import static io.microsphere.constants.SymbolConstants.VERTICAL_BAR;
912
import static io.microsphere.util.ArrayUtils.ofArray;
@@ -30,11 +33,13 @@
3033
import static io.microsphere.util.StringUtils.substringBefore;
3134
import static io.microsphere.util.StringUtils.substringBeforeLast;
3235
import static io.microsphere.util.StringUtils.substringBetween;
36+
import static io.microsphere.util.StringUtils.toStringArray;
3337
import static io.microsphere.util.StringUtils.trimAllWhitespace;
3438
import static io.microsphere.util.StringUtils.trimLeadingWhitespace;
3539
import static io.microsphere.util.StringUtils.trimTrailingWhitespace;
3640
import static io.microsphere.util.StringUtils.trimWhitespace;
3741
import static io.microsphere.util.StringUtils.uncapitalize;
42+
import static java.util.Collections.emptyList;
3843
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3944
import static org.junit.jupiter.api.Assertions.assertEquals;
4045
import 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

Comments
 (0)