【发布时间】:2021-02-09 09:30:20
【问题描述】:
我是 Mockito 的新手,我正在处理匹配器的一个非常奇怪的问题
def fetchById[T: Format](elasticDetails: ESDetails): F[ESResult[T]]
我的弹性搜索客户端有这个定义,问题从我必须通过的通用格式开始。
.fetchById[JsValue](anyObject[ESDetails])
.returns(IO.pure(ESResult(200, value = Some(fakeResponse)))) ```
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at org.specs2.mock.mockito.MockitoMatchers.anyObject(MockitoMatchers.scala:49)
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"));```
//This the error for matchers that i'm getting after I run my tests.
【问题讨论】:
-
fetchById接受两个参数,看看T: Format去糖的内容。另外,不要在 Scala 中使用 mockito,如果你真的无法避免 mock,scalamock 会更好。