Skip to content

Commit ad4f0c9

Browse files
committed
Polish StringUtilsTests
1 parent 2cd1ee8 commit ad4f0c9

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

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

+19-26
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.junit.jupiter.api.Test;
2525
import org.junit.jupiter.params.ParameterizedTest;
2626
import org.junit.jupiter.params.provider.CsvSource;
27+
import org.junit.jupiter.params.provider.NullAndEmptySource;
28+
import org.junit.jupiter.params.provider.ValueSource;
2729

2830
import static org.assertj.core.api.Assertions.assertThat;
2931
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -36,38 +38,29 @@
3638
*/
3739
class StringUtilsTests {
3840

39-
@Test
40-
void hasLengthBlank() {
41-
String blank = " ";
42-
assertThat(StringUtils.hasLength(blank)).isTrue();
43-
}
44-
45-
@Test
46-
void hasLengthNullEmpty() {
47-
assertThat(StringUtils.hasLength(null)).isFalse();
48-
assertThat(StringUtils.hasLength("")).isFalse();
49-
}
50-
51-
@Test
52-
void hasLengthValid() {
53-
assertThat(StringUtils.hasLength("t")).isTrue();
41+
@ParameterizedTest
42+
@ValueSource(strings = {"text", " text ", " ", "\t", "\n text"})
43+
void hasLengthForValidValues(String value) {
44+
assertThat(StringUtils.hasLength(value)).isTrue();
5445
}
5546

56-
@Test
57-
void hasTextBlank() {
58-
String blank = " ";
59-
assertThat(StringUtils.hasText(blank)).isFalse();
47+
@ParameterizedTest
48+
@NullAndEmptySource
49+
void hasLengthForInvalidValues(String value) {
50+
assertThat(StringUtils.hasLength(value)).isFalse();
6051
}
6152

62-
@Test
63-
void hasTextNullEmpty() {
64-
assertThat(StringUtils.hasText(null)).isFalse();
65-
assertThat(StringUtils.hasText("")).isFalse();
53+
@ParameterizedTest
54+
@ValueSource(strings = {"text", " text ", "\n text"})
55+
void hasTextForValidValues(String value) {
56+
assertThat(StringUtils.hasText(value)).isTrue();
6657
}
6758

68-
@Test
69-
void hasTextValid() {
70-
assertThat(StringUtils.hasText("t")).isTrue();
59+
@ParameterizedTest
60+
@NullAndEmptySource
61+
@ValueSource(strings = {" ", "\t"})
62+
void hasTextForInvalidValues(String value) {
63+
assertThat(StringUtils.hasText(value)).isFalse();
7164
}
7265

7366
@Test

0 commit comments

Comments
 (0)