使用 Mockito,是否可以在不提供实际参数的情况下验证是否使用 spy 或 mock 调用了/未调用函数?例如,如果我有一个类或对象:
class MyClass{
def f(x : Int) = x
}
object MyObject{
def f(x : Int) = x
}
我希望能够这样说:
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
我只想验证该方法是否被调用,而不是它接收到特定的参数。另外,当我检查一个函数没有被调用时:
there was no(my_object).f
我不想验证它不是用某些参数调用的,而是根本没有调用它。
有没有办法做到这一点?