I have a list of some objects - let's assume companies. Now I want to check if this list contains companies with some names but not taking order into consideration. Currently I'm using such construction:
companyList.name.sort() == ["First", "Second"]
Is there any operator in Spock or Groovy that allows me to compare arrays without order?
There's no such operator as far as I know. If the list doesn't contain any duplicates the following assertion may be used:
companyList.name as Set == ["First", "Second"] as Set
Or something like that:
companyList.name.size() == ["First", "Second"].size() && companyList.name.containsAll(["First", "Second"])