Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala mockito error value thenReturn is not a member of Nothing #417

Open
5 tasks done
true-eye opened this issue Sep 1, 2020 · 1 comment
Open
5 tasks done

scala mockito error value thenReturn is not a member of Nothing #417

true-eye opened this issue Sep 1, 2020 · 1 comment

Comments

@true-eye
Copy link

true-eye commented Sep 1, 2020

  • The mockito message in the stacktrace have useful information, but it didn't help
  • The problematic code (if that's possible) is copied here;
    Note that some configuration are impossible to mock via Mockito
  • Provide versions (mockito / jdk / os / any other relevant information)
  • Provide a Short, Self Contained, Correct (Compilable), Example of the issue
    (same as any question on stackoverflow.com)
  • Read the contributing guide

I am new to Mockito so this may be a simple issue but I couldn't find a solution

  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 fails as follows

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

Here is the 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]]
    }
  }
}

versions:
Mockito ( mockito-core: 3.3.3, mockito-scala_2.12 )
os ( MacOS )

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

@dwijnand
Copy link

The issue is you're returning a Future[Good[List[User]]] not a Future[List[User]].

@TimvdLippe TimvdLippe transferred this issue from mockito/mockito Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants