Mockito stubbing method with value class argument fails with NullPointerException

浪尽此生 提交于 2019-12-05 13:49:16

It seems to work with scalamock and scalatest. I would still like to find a solution for Mockito tho, so I don't have to change a few hundred tests.

import org.scalatest._
import org.scalamock.scalatest.MockFactory

case class ID[T](val id:Long) extends AnyVal

trait DAO[T]{
  def get(id:ID[T]):T
}

class ScalaMockIDStubTest extends WordSpec with MockFactory{
  import language.postfixOps

  "ScalaMock" should{
    "properly stub with argument value" in {
      val m = stub[DAO[String]
      (m.get _) when(ID[String](1)) returns("abc")
      assert( m.get(ID[String](1)) == "abc")
    }
    "properly stub with argument matcher" in {
      val m = stub[DAO[String]
      (m.get _) when(*) returns("abc")
      assert( m.get(ID[String](1)) == "abc")
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!