以下代码:
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])"
删除泛型无济于事。从存根/验证交换到mock / expected会产生相同的样式编译错误。
我正在使用scala 2.11.0和
"org.scalatest" % "scalatest_2.11" % "2.2.1" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.2" % "test"
任何帮助非常感谢。
答案 0 :(得分:2)
您的错误类型是“验证”#39;方法,应该是Int。 stubService是Service [Int]的类型,容器也是Container [Int] =>在DoesMatch中,您将Int传递给服务
(stubService.doWork _).verify(container.value)