我已经使用 Java 好几年了,但是我是 Scala 的新手,并且仍在尝试找出它的类型系统。我在 Eclipse Scala IDE 3.0.1 中使用 Scala 2.10.2、Slick 1.0.1 和 ScalaMock 2.10-3.0-M4
我正在尝试使用ScalaMock来模拟Slick。updateNameById
def updateNameById(id: Int, input: String, users: RichTable[Object]) = {
users.where(_.id === id).map{ e => e.test }.update(input)
}
abstract class RichTable[T](name: String = "blank")
extends slick.driver.MySQLDriver.simple.Table[T](name) {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def test = column[String]("test")
}
(我实际上是在传递用户:RichTable[User] 其中 User 具有复杂的继承层次结构,但我暂时删除了 User 的使用以简化示例)
users.where
返回 a scala.slick.lifted.Query
,所以我尝试将其模拟如下
class ModelTest extends FlatSpec with MockFactory {
def test = {
val mockUsers = mock[RichTable[Object]]
// mockQuery definition
val mockQuery = mock[scala.slick.lifted.Query[RichTable[Object],
scala.slick.lifted.NothingContainer#TableNothing]]
(mockUsers.where _).expects(*).returns(mockQuery)
Main.updateNameById(1, "asdf", mockUsers)
}
}
mockQuery 定义给了我这些神秘的类型错误
type mismatch;
found : scala.slick.lifted.Query[O(in method union),
scala.slick.lifted.NothingContainer#TableNothing]
required: scala.slick.lifted.Query[(some other)O(in method union),
scala.slick.lifted.NothingContainer#TableNothing]
type mismatch;
found : scala.slick.lifted.Query[O(in method unionAll),
scala.slick.lifted.NothingContainer#TableNothing]
required: scala.slick.lifted.Query[(some other)O(in method unionAll),
scala.slick.lifted.NothingContainer#TableNothing]
我不知道“O(in method union[all])”与“(some other)O(in method union[All])”是什么意思,谷歌没有任何帮助(它没有帮助“其他一些”是一个非常通用的短语 - 谷歌搜索“scala some other type error”产生与“scala type error”几乎相同的结果)。有谁知道这意味着什么和/或如何修复类型错误?