|
|
|
|
@ -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
|
|
|
|
|
@ -783,29 +807,4 @@ class StringUtilsTests {
@@ -783,29 +807,4 @@ class StringUtilsTests {
|
|
|
|
|
assertThat(StringUtils.truncate(text, 10)).isEqualTo(truncated); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@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 delimitedListToStringArray() { |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray(null, ",", null)).isEmpty(); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("a,b,c", null, null)).containsExactly("a,b,c"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("abc", "", null)).containsExactly("a", "b", "c"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("a,b,c", ",", null)).containsExactly("a", "b", "c"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("a,b,c", ",", "a")).containsExactly("", "b", "c"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("a,b,c,", ",", null)).containsExactly("a", "b", "c", ""); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray(",a,b,c", ",", null)).containsExactly("", "a", "b", "c"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("abc", ",", null)).containsExactly("abc"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("a,b,c", ",", ",")).containsExactly("a", "b", "c"); |
|
|
|
|
assertThat(StringUtils.delimitedListToStringArray("a,,b,,c", ",,", null)).containsExactly("a", "b", "c"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|