FlexTradeUKLtd / jfixture

JFixture is an open source library based on the popular .NET library, AutoFixture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OmitAutoPropertyCustomisation needed twice when used with useSubType customisation.

phutchin opened this issue · comments

I'm overriding the behavior for a class, to use a particular extension of that class, and want to omit calling any setters, (as they need unresolvable objects). However to make the OmitAutoPropertyCustomisation work, I need to declare it for both the super class and the sub class. If I use just one or the other, then the setter (declared on the super class) is still called.
To make it work I end up having to do this:

fixture.customise()
                .useSubType(SuperClass.class, SubClass.class)
                .add(new OmitAutoPropertyCustomisation(SuperClass.class))
                .add(new OmitAutoPropertyCustomisation(SubClass.class));

It seems counter intuitive to me, I'd expect to be able to just use new OmitAutoPropertyCustomisation(SuperClass.class)

Good spot - I completely agree.

Some background, the reason this happens is because the fixture is asked to make a SuperClass and this spawns off a request for SubType. The code to auto populate the properties looks at the request object, and it correctly ignores the second request (SubType) but the original request (SuperClass) is still in the stack and tries to populate it.