Simple Generation of Java Beans
Testing Problem
Generating POJOs from their constructor or static factory method in jqwik is rather straightforward through Arbitraries.forType(..). Generating Java beans through property setters requires more effort, e.g. through combinators:
Combinators.withBuilder(MyJavaBean::new)
.use(anyName()).inSetter(MyJavaBean::setFirstName)
.use(anyName()).inSetter(MyJavaBean::setLastName)
.use(anyInitial().injectNull(0.5)).inSetter(MyJavaBean::setInitial)
...
.build();
This requires quite some boilerplate for each property.
Suggested Solution
Provide type based generation of java beans, e.g.
Combinators.forBean(MyJavaBean.class) or Arbitraries.forJavaBeanType(..).
which will try to set all properties using their type as default.
Discussion
Differentiating required/optional bean properties and (partially) specifying dedicated generators for some properties may add quite some complexity to the API.
This seems to be on the backburner because of perceived complexity. Would the JavaBeans spec provide a convenient way to tackle this? Maybe something along the lines of iterating through the class's BeanInfo and working with properties that have a write method? Custom PropertyDescriptor implementations could be implemented to hold the generator metadata.
Actually, I don’t think the implementation would be too complicated. It’s just that I haven’t seen demand for it and I haven’t seen a good DSL/API suggestion for it, yet. Do you have a concrete use case? Do you have an API in mind?