Using Mockito, is it possible to verify that a function was called/not called using a spy or a mock, without giving the actual arguments? For example if I have a class or object:
class MyClass{
def f(x : Int) = x
}
object MyObject{
def f(x : Int) = x
}
I want to be able to say something like:
val my_class = mock[MyClass]
// Do something that causes method f of MyClass to be called
there was one(my_class).f // Doesn't give arguments
val my_object = spy(MyObject)
// Do something that causes method f of MyObject to be called
there was one(my_object).f // Doesn't give arguments
I just want to verify that the method was called, not that it received specific arguments. Also, when I am checking that a function was not called:
there was no(my_object).f
I don't want to verify that it was not called with certain arguments, but that it was not called at all.
Is there any way to do this?
You could use Mockito matchers to specify that you want to verify that the call was made for any argument.
in your case that would be
there was one (my_object/my_class).f(any[Int])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With