Im trying to mock scala call-by name method in mockito. But running into this error.
This exception may occur if matchers are combined with raw value
You can use https://github.com/mockito/mockito-scala
import com.example.{CacheHelper, Command}
import org.mockito.ArgumentMatchersSugar._
import org.mockito.IdiomaticMockito
import org.scalatest.{Matchers, _}
class ExampleSpec extends FlatSpec with Matchers with BeforeAndAfter with IdiomaticMockito {
"it" should "call commands execute" in {
val cacheHelper: CacheHelper = new CacheHelper
val commandMock: Command = mock[Command]
val spyCacheHelper = spy(cacheHelper)
spyCacheHelper.isCircuitBreakerEnabled shouldReturn true
spyCacheHelper.createCommand(any[String], any[Long]) shouldReturn commandMock
val result: Long = spyCacheHelper.getOrElse("key")(1L)
println("result = " + result)
verify(commandMock).execute()
}
}