Reputation: 50064
Is there a way to ask Mockito if a method was called (like verify) but instead of exploding when false, it just would return true/false. Essentially I want to be able to query a mock object in some code I am writing that wraps Mockito, and then handle failures my own way.
Upvotes: 3
Views: 1188
Reputation: 42223
Hi I don't think there is something like that right now. However you can achieve that with a custom VerificationMode
. You could proceed the same way as you will do with a classic visitor pattern, ie you create the VerificationMode
instance, in the verify
method you set some instance variable to either true or false, and finally later on you could check the result by querying your VerificationMode
instance.
Note that you need wrap a verification mode and catch the exception it might throws. (times(1)
is the default verification mode)
Hope that helps.
Upvotes: 1