
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.
61 lines
1.5 KiB
Plaintext
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[]
|