scala - scala mockito错误`value thenReturn不是Nothing的成员`
问题描述
val users = List(User(name = "A"))
val userRepoMock = mock[UserRepo]
"GET /users" should {
"return the users" in {
when(userRepoMock.get()).thenReturn(Future.successful(Good(users)))
当我运行测试时,它不会编译
value thenReturn is not a member of Nothing
[error] L55:
when(userRepoMock.get()).thenReturn(Future.successful(Good(users)))
[error] L55:
谁能帮我解决这个问题,好吗?提前致谢
这是 UserRepo 的定义
trait UserRepo {
def get(): Future[List[User]]
}
object UserRepo {
class ActorImpl @Inject()(actor: UserSyncActor.Ref) extends UserRepo {
override def get(): Future[List[User]] = {
implicit val timeout: Timeout = 10.seconds
actor.ref.ask(UserSyncActor.GetUsers).mapTo[List[User]]
}
}
}
我还在一个模块中将 UserRepo 与其 ActorImpl 链接起来
class ActorsModule extends AbstractModule {
...
override def configure(): Unit = {
val _ = bind(classOf[UserRepo]).to(classOf[UserRepo.ActorImpl])
}
}
解决方案
我最近遇到了类似的问题,对我来说,问题是我在里面返回的thenReturn()
类型与我正在模拟的函数应该返回的类型不同。
在您的情况下,我会仔细检查,Future.successful(Good(users))
但Future[List[User]]
此错误消息非常模糊且无益,因此可能是其他内容
推荐阅读
- ios - iOS:如何在框架内加载 xib
- google-apps-script - 如何在谷歌应用脚本中将字符串转换为 UTF-16 格式
- java - 无法解析我的片段内 getActivity().showQuestion 中的 showQueston 参数
- php - 如何编写此正则表达式以与 preg_match 一起使用?
- ssrs-2008 - SSRS - 报告操作
- python-3.x - 在绘图中设置位置 - Matplotlib Python
- java - Java - Saxon API - 以“追加”模式写入文件
- visual-studio - Clang 3.3 和 Visual Studio
- postgresql - 自动提交在 postgresql 和 psycopg2 中是什么意思?
- laravel - laravel 集合对象中的新属性以 JSON 形式返回