我希望我的模拟能够处理方法的任何输入
val redis = mock[RedisClient]
when(redis.scard(any[String])).thenReturn(Some("hello"))
错误:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!
[info] 2 matchers expected, 1 recorded:
[info] -> at ..(SomeSpec.scala:123)
[info]
[info] This exception may occur if matchers are combined with raw values:
[info] //incorrect:
[info] someMethod(anyObject(), "raw String");
答案 0 :(得分:1)
scard
有两个参数,其中one parameter为implicit:
// SCARD
// Return the number of elements (the cardinality) of the Set at key.
def scard(key: Any)(implicit format: Format): Option[Long] =
send("SCARD", List(key))(asLong)
如果你没有指定参数,Scala会提供一个参数,这会干扰Mockito line up matchers with arguments的能力。
另请参阅:org.specs2.mock.Mockito matchers are not working as expected