>我有一个方法,它已经被嘲笑了,并采用Seq作为参数。
我想检查该方法是用具有相同内容的 Seq 调用的,但与顺序无关。
例如:
myMethod(Seq(0,1)) wasCalled once
如果我们调用myMethod(Seq(1,0))
,则会通过
考虑argThat
匹配器,它可以指定谓词匹配器
argThat((s: Seq[Int]) => s.sorted == Seq(0,1))
例如
import org.scalatest.{FlatSpec, Matchers}
import org.mockito.{ArgumentMatchersSugar, IdiomaticMockito}
trait Qux {
def foo(s: Seq[Int]): Int
}
class ArgThatSpec extends FlatSpec with Matchers with IdiomaticMockito with ArgumentMatchersSugar {
"ArgThat" should "match on a predicate" in {
val qux = mock[Qux]
qux.foo(argThat((s: Seq[Int]) => s.sorted == Seq(0,1))) answers (42)
qux.foo((Seq(1,0))) shouldBe (42)
}
}