Polish StringUtilsTests

This commit is contained in:
Sam Brannen 2024-10-06 15:36:16 +02:00
parent 2cd1ee8a24
commit ad4f0c99bf
1 changed files with 19 additions and 26 deletions

View File

@ -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 @ParameterizedTest
void hasLengthNullEmpty() { @NullAndEmptySource
assertThat(StringUtils.hasLength(null)).isFalse(); void hasLengthForInvalidValues(String value) {
assertThat(StringUtils.hasLength("")).isFalse(); assertThat(StringUtils.hasLength(value)).isFalse();
} }
@Test @ParameterizedTest
void hasLengthValid() { @ValueSource(strings = {"text", " text ", "\n text"})
assertThat(StringUtils.hasLength("t")).isTrue(); void hasTextForValidValues(String value) {
assertThat(StringUtils.hasText(value)).isTrue();
} }
@Test @ParameterizedTest
void hasTextBlank() { @NullAndEmptySource
String blank = " "; @ValueSource(strings = {" ", "\t"})
assertThat(StringUtils.hasText(blank)).isFalse(); void hasTextForInvalidValues(String value) {
} assertThat(StringUtils.hasText(value)).isFalse();
@Test
void hasTextNullEmpty() {
assertThat(StringUtils.hasText(null)).isFalse();
assertThat(StringUtils.hasText("")).isFalse();
}
@Test
void hasTextValid() {
assertThat(StringUtils.hasText("t")).isTrue();
} }
@Test @Test