Browse Source

Polish StringUtilsTests

pull/33665/head
Sam Brannen 1 year ago
parent
commit
ad4f0c99bf
  1. 45
      spring-core/src/test/java/org/springframework/util/StringUtilsTests.java

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

@ -24,6 +24,8 @@ import java.util.Properties; @@ -24,6 +24,8 @@ import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@ -36,38 +38,29 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException @@ -36,38 +38,29 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*/
class StringUtilsTests {
@Test
void hasLengthBlank() {
String blank = " ";
assertThat(StringUtils.hasLength(blank)).isTrue();
}
@Test
void hasLengthNullEmpty() {
assertThat(StringUtils.hasLength(null)).isFalse();
assertThat(StringUtils.hasLength("")).isFalse();
}
@Test
void hasLengthValid() {
assertThat(StringUtils.hasLength("t")).isTrue();
@ParameterizedTest
@ValueSource(strings = {"text", " text ", " ", "\t", "\n text"})
void hasLengthForValidValues(String value) {
assertThat(StringUtils.hasLength(value)).isTrue();
}
@Test
void hasTextBlank() {
String blank = " ";
assertThat(StringUtils.hasText(blank)).isFalse();
@ParameterizedTest
@NullAndEmptySource
void hasLengthForInvalidValues(String value) {
assertThat(StringUtils.hasLength(value)).isFalse();
}
@Test
void hasTextNullEmpty() {
assertThat(StringUtils.hasText(null)).isFalse();
assertThat(StringUtils.hasText("")).isFalse();
@ParameterizedTest
@ValueSource(strings = {"text", " text ", "\n text"})
void hasTextForValidValues(String value) {
assertThat(StringUtils.hasText(value)).isTrue();
}
@Test
void hasTextValid() {
assertThat(StringUtils.hasText("t")).isTrue();
@ParameterizedTest
@NullAndEmptySource
@ValueSource(strings = {" ", "\t"})
void hasTextForInvalidValues(String value) {
assertThat(StringUtils.hasText(value)).isFalse();
}
@Test

Loading…
Cancel
Save