I have an Controller action method that regardless of what happens always returns null, because I want it to reload the same page. (JSF 2.2).
I have successfully used mockito to orchestrate execution down every possible path.
However every path mostly calls an abstract method to add a message or calls a 3rd party library.
So i can assert that it returns null, but that's the case regardless. I see this pattern repeating as development continues.
Problem: I'm always testing for null despite the execution path.
Possible Solutions as I see them:
- I'm very green to mockito, so there might be something else I can do to verify that the 3rd party and abstract methods are called.
I feel that something that could be useful but hacky is a status flag of some sort to know what kind of message was just added to the stack. Hacky because its only real use is that it will be used for testing, as I see it currently.
Reevaluate my methods, in that if I'm in this situation because my code design is wrong.
- I don't have a problem. Leave it as is, and be satisfied that I'm running every execution path and verifying its outcome even thought its the same.
Question: Given what is known, which direction would you consider first to try and solve the problem of verifying internal execution paths externally in a unit test? Or is there a better solution?
Thanks in advance.
Updating with example code to explain verification troubles, if that's the route i should take:
try {
account.save(); //<-- third party object i don't own, & returns void
addInfoMessage("All Updated!"); //<-- abstract method
} catch (final ResourceException e) { //<-- third party exception
addErrorMessage("Sorry your account could not be updated. ");//<-- abstract method
LOG.error("error msg");
}
...
return null;