Skip to content

Instantly share code, notes, and snippets.

@Fristi
Created July 4, 2017 08:57
Show Gist options
  • Save Fristi/bbc9d0e04557278f8d19976188a0b733 to your computer and use it in GitHub Desktop.
Save Fristi/bbc9d0e04557278f8d19976188a0b733 to your computer and use it in GitHub Desktop.
Workaround for Mockito's issue with mocking AnyVal as described here: https://stackoverflow.com/questions/27289757/mockito-matchers-scala-value-class-and-nullpointerexception - requires shapeless
import org.mockito.ArgumentMatchers.{eq => is}
import shapeless.ops.hlist.IsHCons
import shapeless._
trait MockitoScalaMagic {
def isAnyVal[A <: AnyVal, V, VN <: HList](
v: A
)(implicit LB: Generic.Aux[A, VN], ev: IsHCons.Aux[VN, V, HNil], same: (V :: HNil) =:= VN): A =
LB.from(is(ev.head(LB.to(v))) :: HNil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment