diff --git a/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java b/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java index e9d055fbd48..d45e17ed358 100644 --- a/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java @@ -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 { 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 { 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