Created
July 4, 2017 08:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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