Skip to content

Commit

Permalink
Automatically suppresses Warning.ZERO_FIELDS when using #withPrefabVa…
Browse files Browse the repository at this point in the history
…luesForField
  • Loading branch information
jqno committed Sep 17, 2024
1 parent a253cde commit c621fba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nl.jqno.equalsverifier.integration.extended_contract;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException;
import org.junit.jupiter.api.Test;

Expand All @@ -20,7 +19,6 @@ public void succeed_whenRecordHasSinglePrecondition_givenPrefabValuesForField()
EqualsVerifier
.forClass(SinglePrecondition.class)
.withPrefabValuesForField("i", 111, 142)
.suppress(Warning.ZERO_FIELDS)
.verify();
}

Expand Down Expand Up @@ -51,7 +49,6 @@ public void succeed_whenRecordHasDualPrecondition_givenPrefabValueForBothFields(
.forClass(DualPrecondition.class)
.withPrefabValuesForField("x", 111, 142)
.withPrefabValuesForField("y", 505, 555)
.suppress(Warning.ZERO_FIELDS)
.verify();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public <S> SingleTypeEqualsVerifierApi<T> withPrefabValues(Class<S> otherType, S
* Adds prefabricated values for instance fields with a given name (and only the fields with
* the given name) that EqualsVerifier cannot instantiate by itself.
*
* Automatically suppresses {@link Warning.ZERO_FIELDS}, because fields that get a specific
* prefabricated value should usually not be assigned to zero.
*
* @param <S> The class of the prefabricated values.
* @param fieldName The name of the field that the prefabricated values are linked to.
* @param red An instance of {@code S}.
Expand All @@ -129,6 +132,7 @@ public <S> SingleTypeEqualsVerifierApi<T> withPrefabValuesForField(
) {
Validations.validateFieldNameExists(type, fieldName, actualFields);
PrefabValuesApi.addPrefabValuesForField(fieldCache, type, fieldName, red, blue);
suppress(Warning.ZERO_FIELDS);
return this;
}

Expand Down

0 comments on commit c621fba

Please sign in to comment.