Mockito matchers, scala value class and NullPointerException

后端 未结 6 1931
遇见更好的自我
遇见更好的自我 2020-12-15 04:16

I\'m using mockito with scalatest. I have following problem when using matcher with value class.

import org.scalat         


        
6条回答
  •  無奈伤痛
    2020-12-15 05:03

    The newest version of mockito-scala (0.0.9) supports this out of the box, you can do something like

    when(myObj.myMethod(anyVal[MyValueClass]) thenReturn "something"
    
    myObj.myMethod(MyValueClass(456)) shouldBe "something"
    
    verify(myObj).myMethod(eqToVal[MyValueClass](456))
    

    Disclaimer: I'm a developer of that library

提交回复
热议问题