
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.
51 lines
2.6 KiB
Plaintext
51 lines
2.6 KiB
Plaintext
== Why is this an issue?
|
||
|
||
AssertJ assertions taking ``++Consumer++`` objects as arguments are expected to contain "requirements", which should themselves be expressed as assertions. This concerns the following methods: http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractIterableAssert.html#allSatisfy-java.util.function.Consumer-[allSatisfy], http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractIterableAssert.html#anySatisfy-java.util.function.Consumer-[anySatisfy], http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractIterableAssert.html#hasOnlyOneElementSatisfying-java.util.function.Consumer-[hasOnlyOneElementSatisfying], https://tinyurl.com/yxnzt6pj[isInstanceOfSatisfying], http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractIterableAssert.html#noneSatisfy-java.util.function.Consumer-[noneSatisfy], http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractAssert.html#satisfies-java.util.function.Consumer-[satisfies], http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractAssert.html#satisfiesAnyOf-java.util.function.Consumer-java.util.function.Consumer-[satisfiesAnyOf], http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractIterableAssert.html#zipSatisfy-java.lang.Iterable-java.util.function.BiConsumer-[zipSatisfy].
|
||
|
||
|
||
These methods are assuming the ``++Consumer++`` will do the assertions itself. If you do not do any assertion in the ``++Consumer++``, it probably means that you are inadvertently only partially testing your object.
|
||
|
||
|
||
This rule raises an issue when a ``++Consumer++`` argument of any of the above methods does not contain any assertion.
|
||
|
||
|
||
=== Noncompliant code example
|
||
|
||
[source,java]
|
||
----
|
||
assertThat(myObject).isInstanceOfSatisfying(String.class, s -> "Hello".equals(s)); // Noncompliant - not testing the string value
|
||
assertThat(myObject).satisfies("Hello"::equals); // Noncompliant - not testing the string value
|
||
----
|
||
|
||
|
||
=== Compliant solution
|
||
|
||
[source,java]
|
||
----
|
||
assertThat(myObject).isInstanceOfSatisfying(String.class, s -> assertThat(s).isEqualTo("Hello"));
|
||
assertThat(myObject).satisfies(obj -> assertThat(obj).isEqualTo("Hello"));
|
||
----
|
||
|
||
ifdef::env-github,rspecator-view[]
|
||
|
||
'''
|
||
== Implementation Specification
|
||
(visible only on this page)
|
||
|
||
=== Message
|
||
|
||
Primary: Rework this assertion to assert something inside the Consumer argument.
|
||
|
||
Secondary: Argument missing assertion
|
||
|
||
|
||
=== Highlighting
|
||
|
||
Primary: "isInstanceOfSatisfying"/"satisfies"/"allSatisfy"/... method name.
|
||
|
||
|
||
Secondary: The Consumer argument missing assertion
|
||
|
||
|
||
endif::env-github,rspecator-view[]
|