Here is an example of what I try to achieve. Stub always retuns null, but if I change Array(1L)
to *
it works. It seems there is a problem with array arguments.
trait Repo {
def getState(IDs: Array[Long]): String
}
"test" should "pass" in {
val repo = stub[Repo]
(repo.getState _).when(Array(1L)).returns("OK")
val result = repo.getState(Array(1L))
assert(result == "OK")
}
See this post:
Why doesn't Array's == function return true for Array(1,2) == Array(1,2)?
ScalaMock is working fine, but Array equality prevents your expected arg from matching your actual arg.
e.g. this works:
However there is also a way to add a custom matcher(defined in
org.scalamock.matchers.ArgThat
):Update - example for mixed wildcards, literals, argThat: