diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java index 96e0110bc..9727744bf 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java @@ -57,7 +57,15 @@ public void execute(FieldProbe fieldProbe) { return; } - assertEntity(fieldName, "equals", getterName, classProbe.hasMethod(getterName)); + assertTrue( + Formatter.of( + "Class %% doesn't contain getter %%() for field %%.", + classProbe.getType().getSimpleName(), + getterName, + fieldName + ), + classProbe.hasMethod(getterName) + ); Class sub = throwingGetterCreator(getterName); Tuple tuple = valueProvider.provide(new TypeTag(sub)); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java index 5e15749b9..c3611eebc 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java @@ -23,12 +23,10 @@ public SymmetryFieldCheck(SubjectCreator subjectCreator) { public void execute(FieldProbe fieldProbe) { T left = subjectCreator.plain(); T right = subjectCreator.plain(); - T changedLeft = subjectCreator.withFieldChanged(fieldProbe.getField()); T changedRight = subjectCreator.withFieldChanged(fieldProbe.getField()); checkSymmetry(left, right); checkSymmetry(left, changedRight); - checkSymmetry(changedLeft, changedRight); } private void checkSymmetry(T left, T right) { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extra_features/JpaLazyEntityTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extra_features/JpaLazyEntityTest.java index e1a98e78a..e55f2c3eb 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extra_features/JpaLazyEntityTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extra_features/JpaLazyEntityTest.java @@ -21,7 +21,8 @@ public void gettersAreUsed() { public void basicGetterAbsent() { ExpectedException .when(() -> EqualsVerifier.forClass(LazyFieldWithoutGetterContainer.class).verify()) - .assertFailure(); + .assertFailure() + .assertMessageContains("doesn't contain getter getBasic() for field basic"); } @Test diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java index 2ade8be58..0d39f7c59 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java @@ -17,7 +17,7 @@ public class WithPrefabValuesForFieldTest { private final int iBlue = 142; @Test - public void fail_whenRecordHasSinglePrecondition() { + public void fail_whenClassHasSinglePrecondition() { ExpectedException .when(() -> EqualsVerifier @@ -30,7 +30,7 @@ public void fail_whenRecordHasSinglePrecondition() { } @Test - public void succeed_whenRecordHasSinglePrecondition_givenPrefabValuesForField() { + public void succeed_whenClassHasSinglePrecondition_givenPrefabValuesForField() { EqualsVerifier .forClass(SinglePrecondition.class) .withPrefabValuesForField("point", pRed, pBlue) @@ -38,7 +38,7 @@ public void succeed_whenRecordHasSinglePrecondition_givenPrefabValuesForField() } @Test - public void fail_whenRecordHasDualPrecondition() { + public void fail_whenClassHasDualPrecondition() { ExpectedException .when(() -> EqualsVerifier.forClass(DualPrecondition.class).verify()) .assertFailure() @@ -46,7 +46,7 @@ public void fail_whenRecordHasDualPrecondition() { } @Test - public void fail_whenRecordHasDualPrecondition_givenPrefabValuesForOnlyOneField() { + public void fail_whenClassHasDualPrecondition_givenPrefabValuesForOnlyOneField() { ExpectedException .when(() -> EqualsVerifier @@ -59,7 +59,7 @@ public void fail_whenRecordHasDualPrecondition_givenPrefabValuesForOnlyOneField( } @Test - public void succeed_whenRecordHasDualPrecondition_givenPrefabValueForBothFields() { + public void succeed_whenClassHasDualPrecondition_givenPrefabValueForBothFields() { EqualsVerifier .forClass(DualPrecondition.class) .withPrefabValuesForField("x", iRed, iBlue) @@ -134,6 +134,21 @@ public void throw_whenThePrefabValuesAreEqual() { ); } + @Test + public void throw_whenFieldsDontMatch() { + ExpectedException + .when(() -> + EqualsVerifier + .forClass(SinglePrecondition.class) + .withPrefabValuesForField("point", 1, 2) + ) + .assertThrows(IllegalStateException.class) + .assertMessageContains( + "Precondition", + "for field point should be of type FinalPoint but are" + ); + } + @Test public void dontThrow_whenAddingPrefabValuesFromAnotherModuleAndThereforeARedCopyCantBeMade() { EqualsVerifier