Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify that a method was called using Mockito without specifying arguments

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?

like image 696
mushroom Avatar asked Aug 01 '13 00:08

mushroom


1 Answers

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])
like image 85
Ratan Sebastian Avatar answered Sep 19 '22 11:09

Ratan Sebastian