How to set up a method that takes an implicit parameter in scala using Mockito
I get the familiar "Invalid Argument Usage" trying to set a method that takes a regular parameter and an implicit parameter.
trait MyLogger {
def debug(msg: => Any)(implicit context: LoggingContext)
}
val implicit lc = EmptyLoggingContext
val myMock = mock[MyLogger]
when(myMock.debug(any())(any())).thenAnswer(
new Answer[Unit]() {
override def answer(invocation: InvocationOnMock): Unit = ???
}
)
With the above, I get "2 responders, 1 recorded"
If I change it to:
when(myMock.debug(any())).thenAnswer....
I am not getting a pairing error, but the response override is never called.
I've also tried:
when(myMock.debug(any())(any(classOf[LoggingContext]))
which again gives the expected error in 2 responders.
Any suggestions greatly appreciated.
Thank.
UPDATE: The problem here is that msg is a by-name parameter which is not mockable in mockito
+3
source to share
No one has answered this question yet
Check out similar questions: