scala test any() for polymorphic method

157 Views Asked by At
mockedObj = mock[Obj]
when(mockedObj.someMethod(anyString, any(_))).thenAnswer(
  new Answer[Unit] {
    override def answer(invocationOnMock: InvocationOnMock): Unit = {
      // whatever
    }
  }
)

This someMethod is expecting a String, and a function. The someMethod has several implementations, where the functions received are different. This is why I am trying to use any(_) on that 'when' statement.

The error I get is:

Error:(26, 49) missing parameter type for expanded function ((x$1) => any(x$1))
when(mockedObj.someMethod(anyString(), any(_))).thenAnswer(
                             ^

I am not aware if there is a way to place something like 'any' for functions in an abstract way, since I am not concerned in checking that parameter, but I need the mock to pass regardless the function.

Thanks!!

0

There are 0 best solutions below