Scala 无论顺序如何,如何检查使用Seq调用的mock

Scala 无论顺序如何,如何检查使用Seq调用的mock,scala,scalatest,mockito-scala,Scala,Scalatest,Mockito Scala,我有一个方法,它已经被模拟过,并将一个Seq作为参数 我想检查该方法是使用具有相同内容的Seq调用的,但不考虑顺序 例如: myMethod(Seq(0,1)) wasCalled once 如果我们调用myMethodSeq1,0,它将通过考虑matcher,它允许指定谓词匹配器 argThat((s: Seq[Int]) => s.sorted == Seq(0,1)) 比如说 import org.scalatest.{FlatSpec, Matchers} import org

我有一个方法,它已经被模拟过,并将一个Seq作为参数

我想检查该方法是使用具有相同内容的Seq调用的,但不考虑顺序

例如:

myMethod(Seq(0,1)) wasCalled once
如果我们调用myMethodSeq1,0,它将通过考虑matcher,它允许指定谓词匹配器

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)
  }
}
考虑matcher,它允许指定谓词匹配器

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)
  }
}