unclear error for list comparison
oshai opened this issue · 3 comments
oshai commented
I have a code like this:
ProtoTruth.assertThat(myList).reportingMismatchesOnly().ignoringRepeatedFieldOrder()
.displayingDiffsPairedBy { it?.name }
.containsExactly(obj1, obj2)
it is running with two objects:
//expected
id: 1 name: integration 1
id: 2 name: integration 2
//actual
id: 2 name: integration 1
id: 1 name: integration 2
It seems that containsExactly
is ignoring displayingDiffsPairedBy
or at least it doesn't looks like best effort match. or maybe the output is just not clear to me.
here is the simplified output:
Not true that <[id: 1 name: "integration 1", id: 2 name: "integration 2"]>
contains exactly one element that is equivalent according to assertThat(proto).reportingMismatchesOnly().ignoringRepeatedFieldOrder().isEqualTo(target) to each element of <[id: 2 name: "integration 1", id: 2 name: "integration 2"]>.
It is missing an element that corresponds to <id: 2 name: "integration 1">
and has unexpected elements <[id: 1 name: "integration 1" (diff: Differences were found: modified: id: 2 -> 1 )]> with key integration 1
nick-someone commented
I think that: with key integration 1
at the end of the output is the result of your displayingDiffsPairedBy
.
cpovirk commented
(The general issue stands that this message is a wall of text. We've started migrating the ProtoTruth message to the key-value format that most of our assertions use (example), but it's a long process. Sorry for the mess in the meantime.)
oshai commented
Thanks!