rspec/rules/S5833/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

61 lines
1.5 KiB
Plaintext

== Why is this an issue?
Describing, setting error message or adding a comparator in https://assertj.github.io/doc/[AssertJ] must be done before calling the assertion, otherwise, settings will not be taken into account.
This rule raises an issue when one of the method (with all similar methods):
* ``++as++``
* ``++describedAs++``
* ``++withFailMessage++``
* ``++overridingErrorMessage++``
* ``++usingComparator++``
* ``++usingElementComparator++``
* ``++extracting++``
* ``++filteredOn++``
is called without calling an AssertJ assertion afterward.
=== Noncompliant code example
[source,java]
----
assertThat(actual).isEqualTo(expected).as("Description"); // Noncompliant
assertThat(actual).isEqualTo(expected).withFailMessage("Fail message"); // Noncompliant
assertThat(actual).isEqualTo(expected).usingComparator(new CustomComparator()); // Noncompliant
----
=== Compliant solution
[source,java]
----
assertThat(actual).as("Description").isEqualTo(expected);
assertThat(actual).withFailMessage("Fail message").isEqualTo(expected);
assertThat(actual).usingComparator(new CustomComparator()).isEqualTo(expected);
----
== Resources
* https://assertj.github.io/doc/#calling-as-after-the-assertion[AssertJ incorrect usage documentation]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add an assertion predicate after calling this method.
=== Highlighting
Method call identifier
endif::env-github,rspecator-view[]