0

I am using AssertJ fluent assertions in my code. Example:

assertThat(vertexSet).containsExactlyInAnyOrder(v0, v2, v4);

Now I need to use identity comparison instead of .equals(...). What is the simplest way to achieve this?

Here's what I came up with:

assertThat(vertexSet).usingComparator((x, y) -> {
    return x == y ? 0 : -1;
}).containsExactlyInAnyOrder(v0, v2, v4);

This works, but I don't particularly like it. Requires a Comparator implementation which has a bit wider semantics compared to equal/not equal check I am actually interested in.

Are there better options? Other assertions have variants like isEqualTo/isSameAs, but I could not find analogs in IterableAssert.

lexicore
  • 42,748
  • 17
  • 132
  • 221

0 Answers0