A dedicated AssertJ assertion receives the value under test, so its failure message can show that value. For example, when
assertThat(names).contains("Ada") fails, it shows the collection and the missing element.
assertThat(names.contains("Ada")).isTrue() only reports that false was not true.
assertThat(names.contains("Ada")).isTrue(); // Noncompliant
assertThat(names).contains("Ada");
The following catalog is not exhaustive. Similar assertions and negated forms may also be reported. Choose a matcher that expresses the intended test, and check the AssertJ version used by the project.
The object-identity mapping for x == y applies to reference values. Check null and edge-case behavior when replacing a derived
expression: for example, map.get(key) can return null for a missing key, whereas containsEntry(key, null)
requires the key to exist. For floating-point values, check NaN and signed-zero behavior rather than assuming a relational-expression rewrite is
equivalent.
| Original | Dedicated |
|---|---|
|
Related to Object |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related to |
|
|
|
|
|
|
|
|
|
|