Mockito matchers, scala value class and NullPointerException

后端 未结 6 1934
遇见更好的自我
遇见更好的自我 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:04

    The proper solution is:

    case class StringValue(val text: String) extends AnyVal
    case class LongValue(val value: Long) extends AnyVal
    
    val eqFirst: StringValue = StringValue(org.mockito.Matchers.eq("first"))
    val anySecond: StringValue = StringValue(org.mockito.Matchers.any[String])
    
    val eqFirst: LongValue = LongValue(org.mockito.Matchers.eq(1L))
    val anySecond: LongValue = LongValue(org.mockito.Matchers.any[Long])
    

提交回复
热议问题