Browse Source

Merge pull request #33298 from zinzoddari

* pr/33298:
  Polish "Improve test coverage of StringUtils"
  Improve test coverage of StringUtils

Closes gh-33298
pull/33306/head
Stéphane Nicoll 2 years ago
parent
commit
47780747ba
  1. 26
      spring-core/src/test/java/org/springframework/util/StringUtilsTests.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -467,6 +467,18 @@ class StringUtilsTests { @@ -467,6 +467,18 @@ class StringUtilsTests {
assertThat(input[1]).isEqualTo("myString2");
}
@Test
void trimArrayElements() {
assertThat(StringUtils.trimArrayElements(null)).isNull();
assertThat(StringUtils.trimArrayElements(new String[] {})).isEmpty();
assertThat(StringUtils.trimArrayElements(new String[] { "", " ", " ", " " })).containsExactly("", "", "", "");
assertThat(StringUtils.trimArrayElements(new String[] { "\n", "\t ", "\n\t" })).containsExactly("", "", "");
assertThat(StringUtils.trimArrayElements(new String[] { "a", "b", "c" })).containsExactly("a", "b", "c");
assertThat(StringUtils.trimArrayElements(new String[] { " a ", " b b ", " cc " })).containsExactly("a", "b b", "cc");
assertThat(StringUtils.trimArrayElements(new String[] { " a ", "b", " c " })).containsExactly("a", "b", "c");
assertThat(StringUtils.trimArrayElements(new String[] { null, " a ", null })).containsExactly(null, "a", null);
}
@Test
void removeDuplicateStrings() {
String[] input = new String[] {"myString2", "myString1", "myString2"};
@ -558,6 +570,18 @@ class StringUtilsTests { @@ -558,6 +570,18 @@ class StringUtilsTests {
assertThat(sa[0]).isEqualTo("a,b");
}
@Test
void delimitedListToStringArrayWithCharacterToDelete() {
String[] sa = StringUtils.delimitedListToStringArray("a,b,c", ",", "a");
assertThat(sa).containsExactly("", "b", "c");
}
@Test
void delimitedListToStringArrayWithCharacterToDeleteEqualsToDelimiter() {
String[] sa = StringUtils.delimitedListToStringArray("a,b,c", ",", ",");
assertThat(sa).containsExactly("a", "b", "c");
}
@Test
void commaDelimitedListToStringArrayMatchWords() {
// Could read these from files

Loading…
Cancel
Save