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

mockito-scala error value thenAnswer is not a member of Nothing #458

Open
LannyRipple opened this issue Jul 21, 2022 · 0 comments
Open

mockito-scala error value thenAnswer is not a member of Nothing #458

LannyRipple opened this issue Jul 21, 2022 · 0 comments

Comments

@LannyRipple
Copy link

Using Mockito I do not receive the error but when using mockito-scala I do. Code below mirrors the code I'm writing.

scalaVersion: 2.12.16
mockito-scala: 1.17.7

package org.ljr

import org.mockito.AdditionalAnswers._
import org.mockito.ArgumentMatchers._
import org.scalatest.matchers.should._
import org.scalatest.wordspec._
import org.mockito.MockitoSugar

class AnswerSpecMockito extends AnyWordSpec with Matchers {
  import Environment._
  import org.mockito.Mockito._

  val mt = mock(classOf[MockTarget])
  when(mt.addTriggers(any[Foo], any[Bar])).thenAnswer(returnsFirstArg())
}

class AnswerSpecMockitoScala extends AnyWordSpec with Matchers with MockitoSugar {
  import Environment._

  val mt = mock[MockTarget]

/* Compiler error

  [error] /Users/lripple/ip/mockito-scala-example/src/main/scala/org/ljr
  /AnswerSpecMockitoScala.scala:23:44: value thenAnswer is not a member of Nothing
  [error]   when(mt.addTriggers(any[Foo], any[Bar])).thenAnswer(returnsFirstArg())
  [error]                                            ^
*/

  when(mt.addTriggers(any[Foo], any[Bar])).thenAnswer(returnsFirstArg())
}


object Environment {

  case class Foo(a: Int, b: String)

  trait Bar {
    def key: String
  }

  case class BarImpl(key: String, value: String) extends Bar

  class MockTarget {
    def addTriggers(foo: Foo, bar: Bar): Foo = foo.copy(b = bar.key)
  }
}

As a workaround I create the mock and set up thenAnswer in a def of an object which does not extends MockitoSugar.

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

1 participant