4747
4848import static com .github .nylle .javafixture .CustomizationContext .noContext ;
4949import static com .github .nylle .javafixture .SpecimenType .fromClass ;
50+ import static java .lang .String .format ;
5051import static org .assertj .core .api .Assertions .assertThat ;
5152import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
5253
@@ -72,9 +73,9 @@ void throwsExceptionForInvalidCustomization() {
7273
7374 assertThatExceptionOfType (SpecimenException .class )
7475 .isThrownBy (() -> sut .construct (type , context ))
75- .withMessageContaining ("Cannot customize fields because no suitable constructor was found. Candidates are:\n " )
76- .withMessageContaining (" com.github.nylle.javafixture.testobjects.withconstructor.TestObjectWithTwoConstructors(arg0,arg1) (Missing fields: [missingCustomization, missingExclusion])\n " )
77- .withMessageContaining (" com.github.nylle.javafixture.testobjects.withconstructor.TestObjectWithTwoConstructors(arg0) (Missing fields: [missingCustomization, arg1, missingExclusion])" );
76+ .withMessageContaining (format ( "Cannot customize fields because no suitable constructor was found. Candidates are:%n" ) )
77+ .withMessageContaining (format ( " com.github.nylle.javafixture.testobjects.withconstructor.TestObjectWithTwoConstructors(arg0,arg1) (Missing fields: [missingCustomization, missingExclusion])%n" ) )
78+ .withMessageContaining (format ( " com.github.nylle.javafixture.testobjects.withconstructor.TestObjectWithTwoConstructors(arg0) (Missing fields: [missingCustomization, arg1, missingExclusion])" ) );
7879 }
7980
8081 @ Test
@@ -219,6 +220,18 @@ void argumentsCanBeCustomized() {
219220 assertThat (result .getValue ()).isEqualTo ("customized" );
220221 }
221222
223+ @ Test
224+ @ DisplayName ("nested arguments can be customized" )
225+ void nestedArgumentsCanBeCustomized () {
226+ var sut = new InstanceFactory (new SpecimenFactory (new Context (Configuration .configure ())));
227+
228+ var customizationContext = new CustomizationContext (List .of ("arg1.arg1" ), Map .of ("arg1.arg0" , "customized" ), true );
229+ TestObjectWithConstructedField result = sut .construct (fromClass (TestObjectWithConstructedField .class ), customizationContext );
230+
231+ assertThat (result .getTestObjectWithGenericConstructor ().getInteger ()).isNull ();
232+ assertThat (result .getTestObjectWithGenericConstructor ().getValue ()).isEqualTo ("customized" );
233+ }
234+
222235 @ Test
223236 @ DisplayName ("constructor arguments are cached" )
224237 void constructorArgumentsAreNotCached () {
0 commit comments