我正在尝试像这样为Play的WSClient创建模拟:
def mockGet[A](url : String, method : String, headers : Seq[(String, String)], timeout : Duration)(
response: Future[AhcWSResponse]
) =
(mockWsClient
.url(_ : String)
.withMethod(_ : String)
.withHttpHeaders(_: (String, String)*)
.withRequestTimeout(_ : Duration)
.stream())
.expects(url, method, headers, timeout)
.returning(response)
问题是withHttpHeaders
-这实际上需要使用(字符串,字符串)*,但是当我如上所述指定该类型时,会出现这样的编译器错误:
[error] found : Seq[(String, String)]
[error] required: (String, String)
[error] .withHttpHeaders(_: Seq[(String, String)])
我需要为此方法指定什么类型,因为(String,String)不正确。该方法的实际定义是:
override def withHttpHeaders(headers: (String, String)*): Self
尝试
(xs: Seq[(String, String)]) => mockWsClient.withHttpHeaders(xs: _*)