@@ -195,7 +195,7 @@ public void innerBuilderWithAllPropertyConstructor()
195
195
* with the required properties will be created
196
196
*/
197
197
@ Test
198
- public void innerBuilderWithRequiredPropertyConstructor ()
198
+ public void innerBuilderWithRequiredPropertyOnlyConstructor ()
199
199
throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , IllegalAccessException , InstantiationException {
200
200
ClassLoader resultsClassLoader = schemaRule .generateAndCompile ("/schema.useInnerClassBuilders/child.json" , "com.example" ,
201
201
config ("generateBuilders" , true , "useInnerClassBuilders" , true , "includeConstructors" , true , "constructorsRequiredPropertiesOnly" , true ));
@@ -225,6 +225,47 @@ public void innerBuilderWithRequiredPropertyConstructor()
225
225
assertEquals (sharedProperty , getSharedProperty .invoke (childObject ));
226
226
}
227
227
228
+ /**
229
+ * This method confirms that duplicate constructors are not generated (compile time error is not thrown) when:
230
+ * <ul>
231
+ * <li>all properties are required</li>
232
+ * <li>{@code includeAllPropertiesConstructor} configuration property is {@code true}</li>
233
+ * <li>{@code includeRequiredPropertiesConstructor} configuration property is {@code true}</li>
234
+ */
235
+ @ Test
236
+ public void innerBuilderWithRequiredPropertyConstructor () throws ReflectiveOperationException {
237
+ ClassLoader resultsClassLoader = schemaRule .generateAndCompile (
238
+ "/schema.useInnerClassBuilders/child_parent_all_required.json" ,
239
+ "com.example" ,
240
+ config ("generateBuilders" , true ,
241
+ "useInnerClassBuilders" , true ,
242
+ "includeConstructors" , true ,
243
+ "includeAllPropertiesConstructor" , true ,
244
+ "includeRequiredPropertiesConstructor" , true ));
245
+
246
+ Class <?> builderClass = resultsClassLoader .loadClass ("com.example.ChildParentAllRequired$ChildParentAllRequiredBuilder" );
247
+ Constructor <?> constructor = builderClass .getConstructor (String .class , String .class );
248
+ Method buildMethod = builderClass .getMethod ("build" );
249
+ Method withChildProperty = builderClass .getMethod ("withChildProperty" , Integer .class );
250
+
251
+ int childProperty = 1 ;
252
+ String parentProperty = "parentProperty" ;
253
+ String sharedProperty = "sharedProperty" ;
254
+
255
+ Object builder = constructor .newInstance (sharedProperty , parentProperty );
256
+ withChildProperty .invoke (builder , childProperty );
257
+ Object childObject = buildMethod .invoke (builder );
258
+
259
+ Class <?> childClass = resultsClassLoader .loadClass ("com.example.ChildParentAllRequired" );
260
+ Method getChildProperty = childClass .getMethod ("getChildProperty" );
261
+ Method getParentProperty = childClass .getMethod ("getParentProperty" );
262
+ Method getSharedProperty = childClass .getMethod ("getSharedProperty" );
263
+
264
+ assertEquals (childProperty , getChildProperty .invoke (childObject ));
265
+ assertEquals (parentProperty , getParentProperty .invoke (childObject ));
266
+ assertEquals (sharedProperty , getSharedProperty .invoke (childObject ));
267
+ }
268
+
228
269
/**
229
270
* This method confirms that if innerBuilders are used, a "builder" method is created on the class that returns an instance of the builder
230
271
*/
0 commit comments