Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching any parameterless function as an argument in scala Mockito

I'm trying to verify the following method gets called using Mockito:

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

Here's the verification on a mock:

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

And I get the exception:

   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"));

I know this is caused by the last parameterless function. How can I perform a verify properly here?

like image 768
Garrett Hall Avatar asked Nov 04 '22 14:11

Garrett Hall


1 Answers

Could you try Function0[Unit] ?

there was one(notifier).forward(any[ServletRequest])(any[Function0[Unit]])
like image 55
Przemek Avatar answered Nov 09 '22 14:11

Przemek