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

Loading…
Cancel
Save