5

我正在尝试验证使用 Mockito 调用以下方法:

class Notifier {
  def forward(request: ServletRequest)(onFailure: => Unit) : Unit
}

这是模拟的验证:

val notifier = mock[Notifier]
there was one(notifier).forward(any[ServletRequest])(any[() => Unit])

我得到了例外:

   The mock was not called as expected: 
    Invalid use of argument matchers!
    3 matchers expected, 2 recorded.
    This exception may occur if matchers are combined with raw values:
        //incorrect:
        someMethod(anyObject(), "raw String");
    When using matchers, all arguments have to be provided by matchers.
    For example:
        //correct:
        someMethod(anyObject(), eq("String by matcher"));

我知道这是由最后一个无参数函数引起的。如何在此处正确执行验证?

4

1 回答 1

2

你能试试Function0[Unit]吗?

there was one(notifier).forward(any[ServletRequest])(any[Function0[Unit]])
于 2014-12-25T21:59:48.467 回答