Mockito Mocks (Matchers) で Scala の値クラスを使用すると、NullPointerException が発生します。次の例を参照してください。
import org.scalatest.FunSuite
import org.scalatest.mock.MockitoSugar._
import org.mockito.{Matchers, Mockito}
class Id(val underlying: Int) extends AnyVal
class MockitoValueClassSuite extends FunSuite {
trait Sample {
def doIt(id: Id) : Int
}
test("Check value classes in scala with mockito") {
val sampleMock = mock[Sample]
val id = new Id(1)
Mockito.when(sampleMock.doIt(Matchers.eq(id))).thenReturn(5)
assert(sampleMock.doIt(id) == 5)
}
}
結果:
java.lang.NullPointerException was thrown.
java.lang.NullPointerException
at net.gutefrage.service.user.service.MockitoValueClassSuite$$anonfun$1.apply$mcV$sp(MockitoValueClassSuite.scala:21)
at net.gutefrage.service.user.service.MockitoValueClassSuite$$anonfun$1.apply(MockitoValueClassSuite.scala:16)
at net.gutefrage.service.user.service.MockitoValueClassSuite$$anonfun$1.apply(MockitoValueClassSuite.scala:16)
at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
ここで何ができるかヒントはありますか?