Skip to content

Commit

Permalink
Makes more improvements suggested by PITest
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Sep 24, 2024
1 parent 000d5fb commit 2efc52a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> sub = throwingGetterCreator(getterName);
Tuple<T> tuple = valueProvider.<T>provide(new TypeTag(sub));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public SymmetryFieldCheck(SubjectCreator<T> 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);

Check warning on line 28 in equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 28 without causing a test to fail

removed call to checkSymmetry (409 tests run VoidMethodCallMutator)
checkSymmetry(left, changedRight);
checkSymmetry(changedLeft, changedRight);
}

private void checkSymmetry(T left, T right) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WithPrefabValuesForFieldTest {
private final int iBlue = 142;

@Test
public void fail_whenRecordHasSinglePrecondition() {
public void fail_whenClassHasSinglePrecondition() {
ExpectedException
.when(() ->
EqualsVerifier
Expand All @@ -30,23 +30,23 @@ public void fail_whenRecordHasSinglePrecondition() {
}

@Test
public void succeed_whenRecordHasSinglePrecondition_givenPrefabValuesForField() {
public void succeed_whenClassHasSinglePrecondition_givenPrefabValuesForField() {
EqualsVerifier
.forClass(SinglePrecondition.class)
.withPrefabValuesForField("point", pRed, pBlue)
.verify();
}

@Test
public void fail_whenRecordHasDualPrecondition() {
public void fail_whenClassHasDualPrecondition() {
ExpectedException
.when(() -> EqualsVerifier.forClass(DualPrecondition.class).verify())
.assertFailure()
.assertMessageContains("x must be between");
}

@Test
public void fail_whenRecordHasDualPrecondition_givenPrefabValuesForOnlyOneField() {
public void fail_whenClassHasDualPrecondition_givenPrefabValuesForOnlyOneField() {
ExpectedException
.when(() ->
EqualsVerifier
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2efc52a

Please sign in to comment.