mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
326 stars 749 forks source link

Add support for setter methods not starting with set #217

Closed krzysiekbr closed 8 years ago

krzysiekbr commented 8 years ago

Most of classes I'm using in my project have setters starting with "with" keyword and returning "this". For now, if I understand it correctly, it's not possible for me to use Podam because it searches methods starting by "set" keyword and returning void (as per PodamUtils.java)

Is it possible to make Podam search for both of these method prefixes ("set" and "with") or make this prefix configurable?

daivanov commented 8 years ago

Yes, this is possible. You can implement your own version of ClassInfoStrategy or extend AbstractClassInfoStrategy overriding ClassInfoStrategy.getClassInfo(Class<?> pojoClass) and feed this strategy to a Podam factory.

daivanov commented 8 years ago

7.0.1 snapshot available from here.

krzysiekbr commented 8 years ago

Thanks for quick reaction. I wrote my own strategy implementation and it works like a charm.

daivanov commented 8 years ago

Thank you for pointing this out. I've changed AbstractClassInfoStrategy implementation so it's a bit easier to override:

    ClassInfoStrategy classInfoStrategy = new AbstractClassInfoStrategy() {
        @Override
        protected Pattern getGetterPattern() {
            return Pattern.compile("^whatIs");
        }

        @Override
        protected Pattern getSetterPattern() {
            return Pattern.compile("^with");
        }
    };
    PodamFactory factory = new PodamFactoryImpl();
    factory.setClassStrategy(classInfoStrategy);
krzysiekbr commented 8 years ago

That makes everything much easier for me, thanks. When these changes can be released?

daivanov commented 8 years ago

Now Podam 7.0.1 is released, it will appear at some point at Maven repository.