我正在尝试运行以下测试:
import AV_Enums.TimeSeriesFunctions
import org.scalamock.scalatest.MockFactory
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.must.Matchers.{be, _}
import scalaj.http.HttpResponse
import scala.io.Source
class ResponseParserTest extends AnyFunSuite with MockFactory {
test("Parsing from a valid response returns a Right") {
val mockResponse = Source.fromResource("MockResponse.json").mkString
val mockResponse = mock[HttpResponse[String]]
(mockResponse.body _).expects().returning(mockResponse)
ResponseParser.convertTimeSeries(TimeSeriesFunctions.TIME_SERIES_INTRADAY, mockResponse) must be('right)
}
}
然而,我得到了以下构建错误,我不明白是什么原因:
type mismatch;
found : T
required: String
val mockResponse = mock[HttpResponse[String]]
_ must follow method; cannot follow mockResponse.body.type
(mockResponse.body _).expects().returning(mockResponse)
我确信我在ScalaMock的用法上遗漏了一些东西,但我找不到它是什么。
这是ScalaMock中的一个已知错误。试试下面的解决方法,看看这是否能让你继续——它会在嘲笑子类之前锁定类型参数。
test("Parsing from a valid response returns a Right") {
val mockResponse = Source.fromResource("MockResponse.json").mkString
class StringHttpResponse extends HttpResponse[String]("", 0, Map.empty())
val mockResponse = mock[StringHttpResponse]
(mockResponse.body _).expects().returning(mockResponse)
ResponseParser.convertTimeSeries(TimeSeriesFunctions.TIME_SERIES_INTRADAY, mockResponse) must be('right)
}