FlexTradeUKLtd / jfixture

JFixture is an open source library based on the popular .NET library, AutoFixture
MIT License
105 stars 22 forks source link

propertyOf setting for subclass is overridden by superclass auto generation #52

Open jahurska opened 5 years ago

jahurska commented 5 years ago

I have following fixture customization: jFixture.customise() .useSubType(SuperClass.class, SubClass.class) .propertyOf(SubClass.class, "string", "foo") .noResolutionBehaviour().omitSpecimen();

The setString method is only in the SubClass and not in the SuperClass.

Resulting jFixture.create() will result in an object that has auto generated value in the string property and not the overridden value. Debugging inside I found out that it first generates the subtype specimen where the overridden value is correct, but then the superclass auto generation finds the same methods from the specimen (i.e. it will find the setString method) and as there is no override for SuperClass.setString, it will auto generate new string for that property.

I also tested adding .propertyOf(SuperClass.class, "string", "foo"), but that did not help. Probably because the SuperClass does not actually have that method.

I was able to do a workaround for this by adding .add(new OmitAutoPropertyCustomisation(SuperClass.class))