sta-szek / pojo-tester

Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;)
http://www.pojo.pl
GNU Lesser General Public License v3.0
53 stars 26 forks source link

Support for Builder Pattern based class constrution #217

Open niravmsh opened 7 years ago

niravmsh commented 7 years ago

Can we enhance "Create class using selected constructor" to also support Builder Pattern Supplying the object itself or method to generate the object as input to "AbstractAssertion.create"

sta-szek commented 7 years ago

Yes of course, that would be nice. I was thinking about passing method reference as parameter that would create object. But we can tell pojo-tester to use lombok builder so we can increase code coverage on lombok builder as requested in #197.

I imagine implementation as follows (or smth similar): .create(A.class, ACreator::create) - method reference, .create(A.class, ACreator.class) - class reference that implements some kind of Creator interface, .create(A.class).using(ACreator::Create) - same as first, .create(A.class).using(ACreator.class) - same as second, .create(A.class).using(Lombok.Builder) - create using lombok builder,

Or we can introduce some kind of creator / generator and register them as follows: .register(ACreator.class).register(BCreator::class)

We can also register creator automatically, similar to javax.persistence.Converter with autoApply option, but that might be not intuitive and cause global problems.

This topic is quite big and in the near future I won't have time to do this. @niravmsh, would you like to implement this?

sta-szek commented 6 years ago

@niravmsh please check https://github.com/sta-szek/pojo-tester/pull/222 if this satisfies issue reported by you. Thanks.

dkirrane commented 5 years ago

Does this support testing lombak @Builder?