@@ -99,6 +99,21 @@ void dataBindingWithNestedBeanListProperty() throws Exception {
99
99
.hasSize (2 ).extracting ("name" ).containsExactly ("first" , "second" );
100
100
}
101
101
102
+ @ Test // gh-394
103
+ void dataBindingWithNestedBeanSetProperty () throws Exception {
104
+
105
+ String items = IntStream .range (0 , 5 )
106
+ .mapToObj (value -> "{\" name\" :\" test" + value + "\" }" )
107
+ .collect (Collectors .joining ("," ));
108
+
109
+ Object result = this .binder .bind (
110
+ environment ("{\" key\" :{\" items\" :[" + items + "]}}" ), "key" ,
111
+ ResolvableType .forClass (ItemSetHolder .class ));
112
+
113
+ assertThat (result ).isNotNull ().isInstanceOf (ItemSetHolder .class );
114
+ assertThat (((ItemSetHolder ) result ).getItems ()).hasSize (5 );
115
+ }
116
+
102
117
@ Test // gh-301
103
118
void dataBindingWithNestedBeanListEmpty () throws Exception {
104
119
@@ -247,6 +262,28 @@ void primaryConstructorWithNestedBeanList() throws Exception {
247
262
.hasSize (2 ).extracting ("name" ).containsExactly ("first" , "second" );
248
263
}
249
264
265
+ @ Test // gh-410
266
+ void primaryConstructorWithNestedBeanSingletonList () throws Exception {
267
+
268
+ Map <String , String > itemMap = new HashMap <>();
269
+ itemMap .put ("name" , "Joe" );
270
+ itemMap .put ("age" , "37" );
271
+
272
+ Map <String , Object > arguments = new HashMap <>();
273
+ arguments .put ("key" , Collections .singletonMap ("items" , Collections .singletonList (itemMap )));
274
+
275
+ Object result = this .binder .bind (
276
+ DataFetchingEnvironmentImpl .newDataFetchingEnvironment ().arguments (arguments ).build (), "key" ,
277
+ ResolvableType .forClass (PrimaryConstructorItemListBean .class ));
278
+
279
+ assertThat (result ).isNotNull ().isInstanceOf (PrimaryConstructorItemListBean .class );
280
+ List <Item > items = ((PrimaryConstructorItemListBean ) result ).getItems ();
281
+
282
+ assertThat (items ).hasSize (1 );
283
+ assertThat (items .get (0 ).getName ()).isEqualTo ("Joe" );
284
+ assertThat (items .get (0 ).getAge ()).isEqualTo (37 );
285
+ }
286
+
250
287
@ Test
251
288
void primaryConstructorNotFound () {
252
289
assertThatThrownBy (
@@ -353,51 +390,6 @@ void primaryConstructorWithGenericObject() throws Exception {
353
390
Collections .singletonMap ("name" , "second" ));
354
391
}
355
392
356
- @ Test // gh-410
357
- @ SuppressWarnings ("unchecked" )
358
- void coercionWithSingletonList () throws Exception {
359
-
360
- Map <String , String > itemMap = new HashMap <>();
361
- itemMap .put ("name" , "Joe" );
362
- itemMap .put ("age" , "37" );
363
-
364
- Map <String , Object > arguments = new HashMap <>();
365
- arguments .put ("key" , Collections .singletonList (itemMap ));
366
-
367
- DataFetchingEnvironment environment =
368
- DataFetchingEnvironmentImpl .newDataFetchingEnvironment ().arguments (arguments ).build ();
369
-
370
- Object result = this .binder .bind (environment , "key" ,
371
- ResolvableType .forClassWithGenerics (List .class , Item .class ));
372
-
373
- assertThat (result ).isNotNull ().isInstanceOf (List .class );
374
- List <Item > items = (List <Item >) result ;
375
-
376
- assertThat (items ).hasSize (1 );
377
- assertThat (items .get (0 ).getName ()).isEqualTo ("Joe" );
378
- assertThat (items .get (0 ).getAge ()).isEqualTo (37 );
379
- }
380
-
381
- @ Test // gh-392
382
- void shouldHaveHigherDefaultAutoGrowLimit () throws Exception {
383
- String items = IntStream .range (0 , 260 ).mapToObj (value -> "{\" name\" :\" test\" }" ).collect (Collectors .joining ("," ));
384
- Object result = this .binder .bind (
385
- environment ("{\" key\" :{\" items\" :[" + items + "]}}" ), "key" ,
386
- ResolvableType .forClass (ItemListHolder .class ));
387
- assertThat (result ).isNotNull ().isInstanceOf (ItemListHolder .class );
388
- assertThat (((ItemListHolder ) result ).getItems ()).hasSize (260 );
389
- }
390
-
391
- @ Test
392
- void shouldUseTargetCollectionType () throws Exception {
393
- String items = IntStream .range (0 , 5 ).mapToObj (value -> "{\" name\" :\" test" + value + "\" }" ).collect (Collectors .joining ("," ));
394
- Object result = this .binder .bind (
395
- environment ("{\" key\" :{\" items\" :[" + items + "]}}" ), "key" ,
396
- ResolvableType .forClass (ItemSetHolder .class ));
397
- assertThat (result ).isNotNull ().isInstanceOf (ItemSetHolder .class );
398
- assertThat (((ItemSetHolder ) result ).getItems ()).hasSize (5 );
399
- }
400
-
401
393
@ SuppressWarnings ("unchecked" )
402
394
private DataFetchingEnvironment environment (String jsonPayload ) throws JsonProcessingException {
403
395
Map <String , Object > arguments = this .mapper .readValue (jsonPayload , Map .class );
@@ -574,10 +566,6 @@ static class ItemSetHolder {
574
566
575
567
private Set <Item > items ;
576
568
577
- public ItemSetHolder (Set <Item > items ) {
578
- this .items = items ;
579
- }
580
-
581
569
public Set <Item > getItems () {
582
570
return items ;
583
571
}
0 commit comments