|
55 | 55 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
56 | 56 | import static org.springframework.util.ObjectUtils.getIfEmpty; |
57 | 57 | import static org.springframework.util.ObjectUtils.getIfNull; |
| 58 | +import static org.springframework.util.ObjectUtils.getNonNull; |
58 | 59 | import static org.springframework.util.ObjectUtils.isEmpty; |
59 | 60 |
|
60 | 61 | /** |
@@ -118,29 +119,49 @@ void isCompatibleWithThrowsClause() { |
118 | 119 | void getIfNullObject() { |
119 | 120 | String value = UUID.randomUUID().toString(); |
120 | 121 | String backup = UUID.randomUUID().toString(); |
121 | | - assertThat(getIfNull(value, backup)).isEqualTo(value); |
122 | | - assertThat(getIfNull(value, value)).isEqualTo(value); |
123 | | - assertThat(getIfNull(backup, backup)).isEqualTo(backup); |
124 | | - assertThat(getIfNull(null, value)).isEqualTo(value); |
125 | | - assertThat(getIfNull(null, backup)).isEqualTo(backup); |
126 | | - assertThat(getIfNull("null", backup)).isEqualTo("null"); |
127 | | - assertThat(Optional.ofNullable(getIfNull(null, null))).isEmpty(); |
| 122 | + |
| 123 | + assertThat(getIfNull(value, backup)).contains(value); |
| 124 | + assertThat(getIfNull(value, backup)).contains(value); |
| 125 | + assertThat(getIfNull(value, value)).contains(value); |
| 126 | + assertThat(getIfNull(backup, backup)).contains(backup); |
| 127 | + assertThat(getIfNull(null, value)).contains(value); |
| 128 | + assertThat(getIfNull(null, backup)).contains(backup); |
| 129 | + assertThat(getIfNull("null", backup)).contains("null"); |
| 130 | + assertThat(getIfNull(null, null)).isEmpty(); |
128 | 131 | } |
129 | 132 |
|
130 | 133 | @Test |
131 | 134 | void getIfEmptyObject() { |
132 | 135 | Collection<String> empty = Collections.emptyList(); |
133 | 136 | Collection<String> value = List.of(UUID.randomUUID().toString()); |
134 | 137 | Collection<String> backup = List.of(UUID.randomUUID().toString()); |
135 | | - assertThat(getIfEmpty(value, backup)).isEqualTo(value); |
136 | | - assertThat(getIfEmpty(null, backup)).isEqualTo(backup); |
137 | | - assertThat(getIfEmpty(empty, backup)).isEqualTo(backup); |
138 | | - assertThat(getIfEmpty(value, empty)).isEqualTo(value); |
139 | | - assertThat(getIfEmpty(empty, empty)).isEqualTo(empty); |
140 | | - assertThat(getIfEmpty(backup, backup)).isEqualTo(backup); |
141 | | - assertThat(getIfEmpty(null, empty)).isEqualTo(empty); |
142 | | - assertThat(getIfEmpty(null, backup)).isEqualTo(backup); |
143 | | - assertThat(Optional.ofNullable(getIfEmpty(null, null))).isEmpty(); |
| 138 | + |
| 139 | + assertThat(getIfEmpty(value, backup)).contains(value); |
| 140 | + assertThat(getIfEmpty(null, backup)).contains(backup); |
| 141 | + assertThat(getIfEmpty(empty, backup)).contains(backup); |
| 142 | + assertThat(getIfEmpty(value, empty)).contains(value); |
| 143 | + assertThat(getIfEmpty(empty, empty)).contains(empty); |
| 144 | + assertThat(getIfEmpty(backup, backup)).contains(backup); |
| 145 | + assertThat(getIfEmpty(null, empty)).contains(empty); |
| 146 | + assertThat(getIfEmpty(null, backup)).contains(backup); |
| 147 | + assertThat(getIfEmpty(null, null)).isEmpty(); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + void getNonNullObject() { |
| 152 | + String value = UUID.randomUUID().toString(); |
| 153 | + String backup = UUID.randomUUID().toString(); |
| 154 | + |
| 155 | + assertThat(getNonNull(backup, value, value)).contains(backup); |
| 156 | + assertThat(getNonNull(value, null, backup)).contains(value); |
| 157 | + assertThat(getNonNull(backup, value, null)).contains(backup); |
| 158 | + assertThat(getNonNull(value, backup)).contains(value); |
| 159 | + assertThat(getNonNull(null, null, value)).contains(value); |
| 160 | + |
| 161 | + String _null = null; |
| 162 | + assertThat(getNonNull(null, null, _null)).isEmpty(); |
| 163 | + assertThat(getNonNull(null, "null", backup)).contains("null"); |
| 164 | + assertThat(getNonNull(null, null)).isEmpty(); |
144 | 165 | } |
145 | 166 |
|
146 | 167 | @Test |
|
0 commit comments