org.sonar.l10n.java.rules.java.S6103.html Maven / Gradle / Ivy
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: allSatisfy,
anySatisfy,
hasOnlyOneElementSatisfying, isInstanceOfSatisfying, noneSatisfy,
satisfies,
satisfiesAnyOf, 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"));
© 2015 - 2024 Weber Informatics LLC | Privacy Policy