-
Notifications
You must be signed in to change notification settings - Fork 750
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
Relax the POJO definition a bit to handle special cases of mocking needs #86
Comments
First comments that come to my mind. The ultimate goal of PODAM is to fill a POJO state. The strict adherence to JavaBean standards (although we've relaxed it quite a bit already by filling Immutable classes and, where possible, attributes without a setter) allows us to set only attributes. Even in the case above ultimately you want to fill Holder's attributes, only through outer setter methods. Now, one way that we could achieve that would be to invoke all setters in a POJO regardless. But here I think there might lie the problem. What would happen if someone wrote a setter that is not actually a setter and has some nasty side effects? Consider the following case: public class Pojo { private String string1; private String string2; public setString1(String string) {...} public setString2(String string) {...} public setInitialStatus(Bombshell bomb) { } If we were to relax the Javabean rules, Podam would first set string1 and string2 and then ignite a bomb. One could ask: "Why would anyone write code like that?" and the answer is probably no one but that kind of proves my point. Podam is a framework and as such it doesn't have to know whether users write good or bad code. It needs to always work regardless of sensible or meaningless code. The adherence to Javabean standards is a contract between Podam and its users so that it can always fulfil its mission, which is to set a POJO's internal state. How would you suggest Podam deals with the above situation? |
That's one of the two things that came to mind
But then if |
Maybe what we could do is to provide Podam with an additional list of Daniil what do you think? On Saturday, April 11, 2015, mystarrocks notifications@github.com wrote:
|
I will speak about Podam 5.2.1-SNAPSHOT version. In 5.2.0 this is also possible, but code will be slightly different. So what is between you and the success is
It skips all setters, which has no field, because Java contains lots of classes with setters, which breaks PODAM production. So what you need to do is to use custom
Use this strategy with Podam factory
And then attributes get filled:
I hope this helps. |
Daniil, I think what we need is an extraMethods concept where users can add the extra methods they want to execute. These might not only be setters but any method really. I’ve created a local branch issue-86 and I’m trying to implement this concept there. Regards,
|
Well, PODAM already can do it for such simple case. But I see your proposal extremely valuable for another type of beans, those, which have post construction initialization, for example, like this:
|
True, my example was maybe too simple to demonstrate the exact need and |
This has now been implemented in 5.3.1-SNAPSHOT, however Daniil is going to improve my initial commit. Once completed, we’ll be releasing 5.3.1.RELEASE and it’ll be available on Maven central. Regards,
|
Cheers guys, that was quick! |
Fixed in 5.3.0-SNAPSHOT. Will be released in 5.3.0.RELEASE |
Something like this PoDaM user will need to have only these two lines in her/his code:
|
Perfect! Could you please update also the website docs? On Tuesday, April 14, 2015, Daniil Ivanov notifications@github.com wrote:
|
Sure! |
Does this solution accept more than one argument? On Tuesday, April 14, 2015, Daniil Ivanov notifications@github.com wrote:
|
It's variable length arguments list. What worries me, now ExtraMethodExecutorData encapsulates only java.reflect.Method and nothing else. It's good for extension, but from lean development point of view this is waste. |
We can remove it and use simply Method? On Tuesday, April 14, 2015, Daniil Ivanov notifications@github.com wrote:
|
Now it's released. I noticed one more thing: extra methods are places into HashSet, thus, their execution order is not guaranteed. I believe some users might find it useful as List, when they can be sure in which order extra methods will be invoked. |
We often deal with classes that are not
POJO
s in the strict sense of the word, but can very well be argued as ones.Here's an example:
One would think this is one of the good, if not best, candidates
PODAM
could weave its magic on to create a mock object with arbitrary values. But unfortunately,PODAM
won't fill this object with values since it doesn't strictly adhere toJava Bean
standards. IfPODAM
was any less strict to not expect an explicit instance field matching the setter/getter, we'd have had an easier time mocking this type. These lines from thePodamUtils.java
are what holdingPODAM
from being able to mock it:Can
PODAM
be enhanced to relax its definition ofPOJO
a bit so it will be able to handle such special cases of types that need mocking?The text was updated successfully, but these errors were encountered: