@@ -61,7 +61,14 @@ void defaultConstructor() throws Exception {
61
61
void defaultConstructorWithNestedBeanProperty () throws Exception {
62
62
63
63
Object result = initializer .get ().initializeArgument (
64
- environment ("{\" key\" :{\" name\" :\" test name\" ,\" author\" :{\" firstName\" :\" Jane\" ,\" lastName\" :\" Spring\" }}}" ), "key" ,
64
+ environment (
65
+ "{\" key\" :{" +
66
+ "\" name\" :\" test name\" ," +
67
+ "\" author\" :{" +
68
+ " \" firstName\" :\" Jane\" ," +
69
+ " \" lastName\" :\" Spring\" " +
70
+ "}}}" ),
71
+ "key" ,
65
72
ResolvableType .forClass (Book .class ));
66
73
67
74
assertThat (result ).isNotNull ().isInstanceOf (Book .class );
@@ -109,19 +116,29 @@ void primaryConstructor() throws Exception {
109
116
void primaryConstructorWithBeanArgument () throws Exception {
110
117
111
118
Object result = initializer .get ().initializeArgument (
112
- environment ("{\" key\" :{\" item\" :{\" name\" :\" Item name\" },\" name\" :\" Hello\" }}" ), "key" ,
119
+ environment (
120
+ "{\" key\" :{" +
121
+ "\" item\" :{\" name\" :\" Item name\" }," +
122
+ "\" name\" :\" Hello\" ," +
123
+ "\" age\" :\" 30\" }}" ),
124
+ "key" ,
113
125
ResolvableType .forClass (PrimaryConstructorItemBean .class ));
114
126
115
127
assertThat (result ).isNotNull ().isInstanceOf (PrimaryConstructorItemBean .class );
116
- assertThat (((PrimaryConstructorItemBean ) result ).item .name ).isEqualTo ("Item name" );
117
- assertThat (((PrimaryConstructorItemBean ) result ).name ).isEqualTo ("Hello" );
128
+ assertThat (((PrimaryConstructorItemBean ) result ).getItem ().getName ()).isEqualTo ("Item name" );
129
+ assertThat (((PrimaryConstructorItemBean ) result ).getName ()).isEqualTo ("Hello" );
130
+ assertThat (((PrimaryConstructorItemBean ) result ).getAge ()).isEqualTo (30 );
118
131
}
119
132
120
133
@ Test
121
134
void primaryConstructorWithNestedBeanList () throws Exception {
122
135
123
136
Object result = initializer .get ().initializeArgument (
124
- environment ("{\" key\" :{\" items\" :[{\" name\" :\" first\" },{\" name\" :\" second\" }]}}" ), "key" ,
137
+ environment (
138
+ "{\" key\" :{\" items\" :[" +
139
+ "{\" name\" :\" first\" }," +
140
+ "{\" name\" :\" second\" }]}}" ),
141
+ "key" ,
125
142
ResolvableType .forClass (PrimaryConstructorItemListBean .class ));
126
143
127
144
assertThat (result ).isNotNull ().isInstanceOf (PrimaryConstructorItemListBean .class );
@@ -132,11 +149,9 @@ void primaryConstructorWithNestedBeanList() throws Exception {
132
149
@ Test
133
150
void primaryConstructorNotFound () {
134
151
assertThatThrownBy (
135
- () -> {
136
- initializer .get ().initializeArgument (
137
- environment ("{\" key\" :{\" name\" :\" test\" }}" ), "key" ,
138
- ResolvableType .forClass (NoPrimaryConstructorBean .class ));
139
- })
152
+ () -> initializer .get ().initializeArgument (
153
+ environment ("{\" key\" :{\" name\" :\" test\" }}" ), "key" ,
154
+ ResolvableType .forClass (NoPrimaryConstructorBean .class )))
140
155
.isInstanceOf (IllegalStateException .class )
141
156
.hasMessageContaining ("No primary or single unique constructor found" );
142
157
}
@@ -150,9 +165,9 @@ private DataFetchingEnvironment environment(String jsonPayload) throws JsonProce
150
165
151
166
static class SimpleBean {
152
167
153
- String name ;
168
+ private String name ;
154
169
155
- int age ;
170
+ private int age ;
156
171
157
172
public String getName () {
158
173
return this .name ;
@@ -174,7 +189,7 @@ public void setAge(int age) {
174
189
175
190
static class PrimaryConstructorBean {
176
191
177
- final String name ;
192
+ private final String name ;
178
193
179
194
public PrimaryConstructorBean (String name ) {
180
195
this .name = name ;
@@ -186,30 +201,28 @@ public String getName() {
186
201
}
187
202
188
203
189
- static class NoPrimaryConstructorBean {
190
-
191
- NoPrimaryConstructorBean (String name ) {
192
- }
193
-
194
- NoPrimaryConstructorBean (String name , Long id ) {
195
- }
196
- }
204
+ static class PrimaryConstructorItemBean {
197
205
206
+ private final String name ;
198
207
199
- static class PrimaryConstructorItemBean {
200
- final String name ;
208
+ private final int age ;
201
209
202
- final Item item ;
210
+ private final Item item ;
203
211
204
- public PrimaryConstructorItemBean (String name , Item item ) {
212
+ public PrimaryConstructorItemBean (String name , int age , Item item ) {
205
213
this .name = name ;
214
+ this .age = age ;
206
215
this .item = item ;
207
216
}
208
217
209
218
public String getName () {
210
219
return this .name ;
211
220
}
212
221
222
+ public int getAge () {
223
+ return this .age ;
224
+ }
225
+
213
226
public Item getItem () {
214
227
return item ;
215
228
}
@@ -218,7 +231,7 @@ public Item getItem() {
218
231
219
232
static class PrimaryConstructorItemListBean {
220
233
221
- final List <Item > items ;
234
+ private final List <Item > items ;
222
235
223
236
public PrimaryConstructorItemListBean (List <Item > items ) {
224
237
this .items = items ;
@@ -230,9 +243,19 @@ public List<Item> getItems() {
230
243
}
231
244
232
245
246
+ static class NoPrimaryConstructorBean {
247
+
248
+ NoPrimaryConstructorBean (String name ) {
249
+ }
250
+
251
+ NoPrimaryConstructorBean (String name , Long id ) {
252
+ }
253
+ }
254
+
255
+
233
256
static class ItemListHolder {
234
257
235
- List <Item > items ;
258
+ private List <Item > items ;
236
259
237
260
public List <Item > getItems () {
238
261
return this .items ;
@@ -246,7 +269,7 @@ public void setItems(List<Item> items) {
246
269
247
270
static class Item {
248
271
249
- String name ;
272
+ private String name ;
250
273
251
274
public String getName () {
252
275
return this .name ;
0 commit comments