Skip to content

Recursive Fields Generator #258

@jsuskalo-kingland

Description

@jsuskalo-kingland

Right now there's a convenient way to generate data based on the fields of a class with the @From(Fields.class) annotation placed on the argument to a function, but this has a problem that if not all the fields have registered generators, then it will fail to generate the value.
It would be very helpful to developers working with nested data structures to be able to have something like @From(RecursiveFields.class) which would then generate each field using a fields generator. This would greatly simplify working with nested POJOs and remove a lot of boilerplate that looks like so:

public class SomeDataClassGen extends Generator<SomeDataClass> {
    public SomeDataClassGen() {
        super(SomeDataClass.class);
    }

    public SomeDataClass generate(SourceOfRandomness r, GenerationStatus s) {
        return gen().fieldsOf(SomeDataClass.class).generate(r, s);
    }
}

This also makes it easier to deal with the POJOs in a case where in most situations you can just use a base generator from fields, but later introduce a generator specific to the class, but without breaking older tests or significantly changing the semantics of the generators for said old tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions