True
True

Reputation: 736

scala mockito error `value thenReturn is not a member of 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)))

When I run the test, it doesn't compile

   value thenReturn is not a member of Nothing
   [error]      L55:      
   when(userRepoMock.get()).thenReturn(Future.successful(Good(users)))
   [error]      L55:          

Could anyone can help me to fix this issue, please? Thanks in advance

Here is a definition of 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]]
    }
  }
}

I also linked the UserRepo with its ActorImpl in a module

class ActorsModule extends AbstractModule {
  ...

  override def configure(): Unit = {
    val _ = bind(classOf[UserRepo]).to(classOf[UserRepo.ActorImpl])
  }
}

Upvotes: 1

Views: 1855

Answers (1)

Ross
Ross

Reputation: 21

I faced a similar issue recently, for me the issue was that what I was returning inside the thenReturn() was a different type to what the function I was mocking should return.

In your case I'd double check that Future.successful(Good(users)) is Future[List[User]] but this error message is pretty vague and unhelpful so could be something else

Upvotes: 2

Related Questions