|
24 | 24 | import org.junit.jupiter.api.Test; |
25 | 25 | import org.junit.jupiter.params.ParameterizedTest; |
26 | 26 | import org.junit.jupiter.params.provider.CsvSource; |
| 27 | +import org.junit.jupiter.params.provider.NullAndEmptySource; |
| 28 | +import org.junit.jupiter.params.provider.ValueSource; |
27 | 29 |
|
28 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
29 | 31 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
|
36 | 38 | */ |
37 | 39 | class StringUtilsTests { |
38 | 40 |
|
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(); |
54 | 45 | } |
55 | 46 |
|
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(); |
60 | 51 | } |
61 | 52 |
|
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(); |
66 | 57 | } |
67 | 58 |
|
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(); |
71 | 64 | } |
72 | 65 |
|
73 | 66 | @Test |
|
0 commit comments