Skip to content

Commit 4778074

Browse files
committed
Merge pull request #33298 from zinzoddari
* pr/33298: Polish "Improve test coverage of StringUtils" Improve test coverage of StringUtils Closes gh-33298
2 parents f63fc01 + ec9d29e commit 4778074

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

spring-core/src/test/java/org/springframework/util/StringUtilsTests.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -467,6 +467,18 @@ void sortStringArray() {
467467
assertThat(input[1]).isEqualTo("myString2");
468468
}
469469

470+
@Test
471+
void trimArrayElements() {
472+
assertThat(StringUtils.trimArrayElements(null)).isNull();
473+
assertThat(StringUtils.trimArrayElements(new String[] {})).isEmpty();
474+
assertThat(StringUtils.trimArrayElements(new String[] { "", " ", " ", " " })).containsExactly("", "", "", "");
475+
assertThat(StringUtils.trimArrayElements(new String[] { "\n", "\t ", "\n\t" })).containsExactly("", "", "");
476+
assertThat(StringUtils.trimArrayElements(new String[] { "a", "b", "c" })).containsExactly("a", "b", "c");
477+
assertThat(StringUtils.trimArrayElements(new String[] { " a ", " b b ", " cc " })).containsExactly("a", "b b", "cc");
478+
assertThat(StringUtils.trimArrayElements(new String[] { " a ", "b", " c " })).containsExactly("a", "b", "c");
479+
assertThat(StringUtils.trimArrayElements(new String[] { null, " a ", null })).containsExactly(null, "a", null);
480+
}
481+
470482
@Test
471483
void removeDuplicateStrings() {
472484
String[] input = new String[] {"myString2", "myString1", "myString2"};
@@ -558,6 +570,18 @@ void delimitedListToStringArrayWithNullDelimiter() {
558570
assertThat(sa[0]).isEqualTo("a,b");
559571
}
560572

573+
@Test
574+
void delimitedListToStringArrayWithCharacterToDelete() {
575+
String[] sa = StringUtils.delimitedListToStringArray("a,b,c", ",", "a");
576+
assertThat(sa).containsExactly("", "b", "c");
577+
}
578+
579+
@Test
580+
void delimitedListToStringArrayWithCharacterToDeleteEqualsToDelimiter() {
581+
String[] sa = StringUtils.delimitedListToStringArray("a,b,c", ",", ",");
582+
assertThat(sa).containsExactly("a", "b", "c");
583+
}
584+
561585
@Test
562586
void commaDelimitedListToStringArrayMatchWords() {
563587
// Could read these from files

0 commit comments

Comments
 (0)