22 lines
2.2 KiB
Plaintext
22 lines
2.2 KiB
Plaintext
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
|
||
|
||
----
|
||
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
|
||
|
||
----
|
||
assertThat(myObject).isInstanceOfSatisfying(String.class, s -> assertThat(s).isEqualTo("Hello"));
|
||
assertThat(myObject).satisfies(obj -> assertThat(obj).isEqualTo("Hello"));
|
||
----
|