|
32 | 32 | import com.fasterxml.jackson.databind.ObjectMapper;
|
33 | 33 | import graphql.schema.DataFetchingEnvironment;
|
34 | 34 | import graphql.schema.DataFetchingEnvironmentImpl;
|
| 35 | +import org.assertj.core.api.CollectionAssert; |
35 | 36 | import org.junit.jupiter.api.Test;
|
36 | 37 |
|
37 | 38 | import org.springframework.core.ResolvableType;
|
@@ -281,6 +282,44 @@ void shouldUseTargetCollectionType() throws Exception {
|
281 | 282 | assertThat(((ItemSetHolder) result).getItems()).hasSize(5);
|
282 | 283 | }
|
283 | 284 |
|
| 285 | + @Test |
| 286 | + @SuppressWarnings("unchecked") |
| 287 | + void list() throws Exception { |
| 288 | + Object result = this.binder.bind( |
| 289 | + environment("{\"key\": [\"1\", \"2\", \"3\"]}"), |
| 290 | + "key", |
| 291 | + ResolvableType.forClassWithGenerics(List.class, String.class) |
| 292 | + ); |
| 293 | + |
| 294 | + assertThat(result).isNotNull().isInstanceOf(List.class); |
| 295 | + new CollectionAssert<>((List<String>) result).containsExactly("1", "2", "3"); |
| 296 | + } |
| 297 | + |
| 298 | + @Test |
| 299 | + @SuppressWarnings("unchecked") |
| 300 | + void listWithNullItem() throws Exception { |
| 301 | + Object result = this.binder.bind( |
| 302 | + environment("{\"key\": [\"1\", null, \"3\"]}"), |
| 303 | + "key", |
| 304 | + ResolvableType.forClassWithGenerics(List.class, String.class) |
| 305 | + ); |
| 306 | + |
| 307 | + assertThat(result).isNotNull().isInstanceOf(List.class); |
| 308 | + new CollectionAssert<>((List<String>) result).containsExactly("1", null, "3"); |
| 309 | + } |
| 310 | + |
| 311 | + @Test |
| 312 | + @SuppressWarnings("unchecked") |
| 313 | + void emptyList() throws Exception { |
| 314 | + Object result = this.binder.bind( |
| 315 | + environment("{\"key\": []}"), |
| 316 | + "key", |
| 317 | + ResolvableType.forClassWithGenerics(List.class, String.class) |
| 318 | + ); |
| 319 | + |
| 320 | + assertThat(result).isNotNull().isInstanceOf(List.class); |
| 321 | + new CollectionAssert<>((List<String>) result).isEmpty(); |
| 322 | + } |
284 | 323 |
|
285 | 324 | @SuppressWarnings("unchecked")
|
286 | 325 | private DataFetchingEnvironment environment(String jsonPayload) throws JsonProcessingException {
|
|
0 commit comments