OpenPojo / openpojo

POJO Testing & Identity Management Made Trivial
http://openpojo.com
Apache License 2.0
156 stars 40 forks source link

Looking for way to validate "fluent setters" or builder pattern #122

Open davidmichaelkarr opened 6 years ago

davidmichaelkarr commented 6 years ago

In many of the pojos I construct, I create "fluent setters", whose name is the property name. They call the setter, and return this. This is a simplification of the builder pattern. I want to validate these methods. I can simply use the code that I wrote a while ago before I discovered OpenPOJO, but it makes sense for this sort of thing to be done in a common framework.

I can see that the problem with validating fluent setters or the builder pattern is that there are variations of these (for instance, adding a "with" prefix). If you just assumed a static convention, it would be straightforward to do, but then it wouldn't be useful to the person who uses the variation that doesn't fit the pattern you settle on.

I'd suggest if you implemented a "FluentSetterTester", you make it parameterizable (for instance, a "prefix" parameter).

Alternatively, it might be more practical to simply publish more information about writing extensions, to facilitate my writing my own "FluentSetterTester". I've briefly looked at "SetterTester", and it looks like it might be pretty easy to write this. I guess I'll attempt this.

gsuero commented 5 years ago

Was this ever followed/implemented? I am looking into a library that can tests my POJOS with getter only and have builders in them.