以下代码:
import org.scalamock.scalatest.MockFactory
import org.scalatest.FlatSpec
case class Container[T](value: T)
trait Service[T] {
def doWork(value: T): Unit
}
class DoesMatch[T](service: Service[T]) {
def doMatch(container: Container[T]) = container match {
case Container(value) => service.doWork(value)
}
}
class TestScalaMock extends FlatSpec with MockFactory {
"Scala Mock" should "verify my call" in {
val stubService = stub[Service[Int]]
val matcher = new DoesMatch[Int](stubService)
val container = Container(2)
matcher.doMatch(container)
(stubService.doWork _).verify(container)
}
}
给出一个编译错误“使用替代方法验证重载方法值:(matcher: org.scalamock.FunctionAdapter1[Int,Booleam]) org.scalamock.CallHandler1[Int,Unit] with org.scalamock.Verify (v1: org.scalamock.MockParameter [Int]") org.scalamock.CallHandler1[Int,Unit] 和 org.scalamock.Verify 不能应用于 (xyContainer[Int])"
删除泛型没有帮助。从 stub/verify 切换到 mock/expects 会产生相同的编译错误。
我正在使用 scala 2.11.0
"org.scalatest" % "scalatest_2.11" % "2.2.1" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.2" % "test"
非常感谢任何帮助。