mguymon / model-citizen

Annotation based model factory for Java
Apache License 2.0
94 stars 13 forks source link

MappedList of MappedList #6

Closed ldonnet closed 11 years ago

ldonnet commented 11 years ago

Hi Michael,

I have searched desesperatly a framework like FactoryGirl in java and I find yours. It's awesome and very cool. I use it for my test now but I have a strange effect when I create MappedList of MappedList.

I have this Line class which call a Route Class which call a StopPoint class. But stopPoints object are not created when I create a line. I've got an empty array. Do you have a limit when we create objects?

@Blueprint(Line.class)
public class LineBlueprint {

    @Default
    String name = "Line";   

    @MappedList(target = Route.class, size = 2)
    List<Route> routes;
}

Which call an other class

@Blueprint(Route.class)
public class RouteBlueprint {

    @Default
    String name = "1001101070001";    

    @MappedList(target = StopPoint.class, size = 6)
    List<StopPoint> stopPoints;    
}
@Blueprint(StopPoint.class)
public class StopPointBlueprint {   

    @Default
    String name = "A";
}
mguymon commented 11 years ago

There should be no limit on the depth of nested mapped fields, I suspect that when the MappedList is being built in the ModelFactory that is is not checking contents of the MappList to see if it matches a Blueprint.

mguymon commented 11 years ago

I suspect I know the problem, if the Route model has List<StopPoiints> set to an empty ArrayList, the ModelFactory will never override it with the Blueprint since it think the value has already been set. This has bitten me before and should be marked as a bug to be fixed.

...

I created a simple test of nested MappListss that is working with, Car -> Wheel -> Options

https://github.com/mguymon/model-citizen/blob/master/src/test/java/com/tobedevoured/modelcitizen/field/MappedListFieldTest.java

ldonnet commented 11 years ago

Thanks a lot! With your work I can do it :

    @MappedList(target = StopPoint.class, size = 6, ignoreEmpty = false)
    List<StopPoint> stopPoints;