I have recently started exploring property based testing using junit-quickcheck. I came across an usecase where a property has to take a list of entities(I have a generator for a standalone entity). I have tried with the code below and it always gives an empty list.
@Property(trials = 5)
public void addingInDiffOrderResultsInSameResult(
List<@From(CusObjGen.class) CusObj> objs) {
}
Can someone show some right way here?
I got it worked by creating another generator that generates list of entities using the entity-generator that was already present like this:
public class CusObjListGenerator extends Generator<List> {
public CusObjListGenerator () {
super(List.class);
}
@Override
public List<CusObj> generate(SourceOfRandomness random, GenerationStatus status) {
CusObjGen generator = gen().make(CusObjGen.class);
List<CusObj> objs = new ArrayList<>();
int randomNoOfEvents = random.nextInt(1, 15);
for (int i = 1; i <= randomNoOfEvents; i++) {
objs.add(generator.generate(random, status));
}
return objs;
}
}