diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java index b71e0469c..1ac23362c 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java @@ -146,10 +146,10 @@ private int countFalses(boolean... bools) { } private class SignificantFieldCheck implements FieldInspector.FieldCheck { - private final boolean skipTestBecause0AndNullBothHaveA0HashCode; + private final boolean skipCertainTestsThatDontMatterWhenValuesAreNull; public SignificantFieldCheck(boolean skipTestBecause0AndNullBothHaveA0HashCode) { - this.skipTestBecause0AndNullBothHaveA0HashCode = skipTestBecause0AndNullBothHaveA0HashCode; + this.skipCertainTestsThatDontMatterWhenValuesAreNull = skipTestBecause0AndNullBothHaveA0HashCode; } @Override @@ -185,7 +185,7 @@ private void assertEqualsAndHashCodeRelyOnSameFields(boolean equalsChanged, bool if (equalsChanged != hashCodeChanged) { boolean skipEqualsHasMoreThanHashCodeTest = - warningsToSuppress.contains(Warning.STRICT_HASHCODE) || skipTestBecause0AndNullBothHaveA0HashCode; + warningsToSuppress.contains(Warning.STRICT_HASHCODE) || skipCertainTestsThatDontMatterWhenValuesAreNull; if (!skipEqualsHasMoreThanHashCodeTest) { Formatter formatter = Formatter.of( "Significant fields: equals relies on %%, but hashCode does not." + @@ -211,7 +211,7 @@ private void assertFieldShouldBeIgnored(boolean equalToItself, boolean equalsCha assertTrue(Formatter.of("Significant fields: equals does not use %%, or it is stateless.", fieldName), fieldShouldBeIgnored || equalsChanged); assertTrue(Formatter.of("Significant fields: equals should not use %%, but it does.", fieldName), - !fieldShouldBeIgnored || !equalsChanged); + !fieldShouldBeIgnored || !equalsChanged || skipCertainTestsThatDontMatterWhenValuesAreNull); } } @@ -223,9 +223,9 @@ private boolean shouldAllFieldsBeUsed(FieldAccessor referenceAccessor) { private boolean isFieldEligible(FieldAccessor referenceAccessor) { return !referenceAccessor.fieldIsStatic() && - !referenceAccessor.fieldIsTransient() && - !referenceAccessor.fieldIsEmptyOrSingleValueEnum() && - !classAccessor.fieldHasAnnotation(referenceAccessor.getField(), SupportedAnnotations.TRANSIENT); + !referenceAccessor.fieldIsTransient() && + !referenceAccessor.fieldIsEmptyOrSingleValueEnum() && + !classAccessor.fieldHasAnnotation(referenceAccessor.getField(), SupportedAnnotations.TRANSIENT); } } diff --git a/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/SignificantFieldsTest.java b/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/SignificantFieldsTest.java index 52e1e67c1..2d0baf7fe 100644 --- a/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/SignificantFieldsTest.java +++ b/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/SignificantFieldsTest.java @@ -306,6 +306,13 @@ public void succeed_whenUsedFieldIsStateless_givenAllFieldsWarningIsSuppressed() .verify(); } + @Test + public void succeed_whenUsedFieldIsStateless_givenStatelessFieldIsIgnored() { + EqualsVerifier.forClass(UsedStatelessContainer.class) + .withIgnoredFields("statelessField") + .verify(); + } + @Test public void succeed_whenClassIsStateless_givenAllFieldsWarningIsSuppressed() { EqualsVerifier.forClass(Stateless.class)