mardi 14 août 2018

How to verify if method was called with set of specified elements in Spock?

I have a test in Spock:

def repository= Mock(Repository)

@Subject
def service = new Service(repository)

def "test"() {
  given:
  def results = [ /* does not matter */ ]

  def element = XYZ

  when:
  def found = service.findByElement(element)

  then:
  1 * repository.findByElements(_ as Set) >> results 
}

which is working properly. But I would like to verify if repository.findByElements method is taking one element set with our specific element. How to achieve this?

Neither this:

1 * repository.findByElements([element] as Set) >> results

nor this:

1 * repository.findByElements({ assert it == [element] as Set }) >> results

does not work.

Aucun commentaire:

Enregistrer un commentaire