我正在尝试使用 Mockito 为 Web 服务编写一个模拟。模拟应该使用 play WS 库模拟 POST 请求。
/**
* Mock for the Web Service
*/
case class WSMock() extends Mockito {
val wsRequestHolder: play.api.libs.ws.WS.WSRequestHolder = mock[play.api.libs.ws.WS.WSRequestHolder]
val wsResponse: play.api.libs.ws.Response = mock[play.api.libs.ws.Response]
wsResponse.status returns 200
wsResponse.body returns "BODY RESP FROM WS"
val futureResponse = scala.concurrent.Future { wsResponse }
wsRequestHolder.post(any[Map[String,Seq[String]]]) returns futureResponse
}
运行测试时出现以下错误:
[error] InvalidUseOfMatchersException:
[error] Invalid use of argument matchers!
[error] 3 matchers expected, 1 recorded:
[error] -> at org.specs2.mock.mockito.MockitoMatchers$class.any(MockitoMatchers.scala:24)
[error]
[error] This exception may occur if matchers are combined with raw values:
[error] //incorrect:
[error] someMethod(anyObject(), "raw String");
[error] When using matchers, all arguments have to be provided by matchers.
[error] For example:
[error] //correct:
[error] someMethod(anyObject(), eq("String by matcher"));
[error]
[error] For more info see javadoc for Matchers class.
在我看来,使用复杂类型(带有嵌套类型参数)的 any[...] 表达式没有正确解析为匹配器。但是,我看不出原始类型在哪里发挥作用。为参数指定这样的匹配器的正确方法是什么Map[String,Seq[String]]
?
非常感谢!