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 に答える