-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive Fields Generator #258
Comments
@jsuskalo Thanks for this suggestion. TBH, when I first put together junit-quickcheck I wasn't sure whether developers would take to Instead of going after |
My initial thought was that the entire tree would be generated strictly as if by the |
@jsuskalo Maybe |
Yeah, that makes a lot of sense to me, however I'm not sure I'm a fan of changing the gen methods to give an optional generator, since that would break existing callers. So it sounds to me like the semantics should be as follows:
I also don't think that we need extra instances of So to fetch a particular generator for a given field, we might be able to just use something like this: Generator<?> fieldGenerator = gen().typeIfExists(field.getType()).orElse(this);
if (fieldGenerator != this) {
// ... configure the generator ...
}
Object value = fieldGenerator.generate(random, status); |
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: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.
The text was updated successfully, but these errors were encountered: