EqualityComparisonAssertion¶
Issue ID EqualityComparisonAssertion ·
Severity Warning ·
Category Usability ·
Default on
Flags assertThat(a == b) (and a != b) where assertk's isEqualTo /
isNotEqualTo should be used.
Why¶
Wrapping the comparison in assertThat and then asserting on the resulting
Boolean produces a useless failure message ("expected true, got false").
isEqualTo shows both sides of the comparison and uses assertk's diffing for
collections and data classes (see also isDataClassEqualTo).
Example¶
Quick fix¶
Yes — the IDE picks the non-literal side as the subject, the
literal/string-template side as the expected value, and rewrites
isTrue()/isFalse() to isEqualTo/isNotEqualTo.
| Pattern | Becomes |
|---|---|
assertThat(a == b).isTrue() |
assertThat(a).isEqualTo(b) |
assertThat(a == b).isFalse() |
assertThat(a).isNotEqualTo(b) |
assertThat(a != b).isTrue() |
assertThat(a).isNotEqualTo(b) |
assertThat(a != b).isFalse() |
assertThat(a).isEqualTo(b) |