I have a method that's declared as returning `Set&...
# kotest
j
I have a method that's declared as returning
Set<MyType>
. I'm writing a test that uses
shouldContainExactly
to test it. When I instantiate the return value as a
LinkedHashSet
it works, but when I instead instantiate it as a
HashSet
I get:
Copy code
Disallowed: Set can be compared only to Set
java.lang.AssertionError: Disallowed: Set can be compared only to Set
May not compare HashSet with ArrayList
expected:<*> but was:<*>
What's going on here?
Oh, I guess
shouldContainExactly
requires the set to be ordered - what matcher should I use to match an unordered collection? (Also, that error message is terrible.)
l
shouldContainExactlyInAnyOrder, I think
j
Yep, that worked, thanks
I'll file a bug report about the error message.
­čÖĆ 1
s
is shouldContainExactly the same as just shouldBe in this case?
j
I think for shouldBe you'd have to construct the
LinkedHashSet
, and it'd fail if the actual type was a subtype? But I'm not sure
s
That makes sense