The type of {@code T}'s first generic parameter.
* @param The type of {@code T}'s second generic parameter.
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/Warning.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/Warning.java
index 7d151f2a9..c6fb0f720 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/Warning.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/Warning.java
@@ -13,108 +13,119 @@ public enum Warning {
* EqualsVerifier} will not fail if one or more fields do not affect the outcome of {@code
* equals}.
*
- * Only applies to non-transient fields.
+ *
+ * Only applies to non-transient fields.
*/
ALL_FIELDS_SHOULD_BE_USED,
/**
* Signals that non-final fields are not relevant in the {@code equals} contract. {@code
- * EqualsVerifier} will not fail if one or more non-final fields do not affect the outcome of
- * {@code equals}.
+ * EqualsVerifier} will not fail if one or more non-final fields do not affect the outcome of {@code equals}.
*
- *
Only applies to non-transient fields.
+ *
+ * Only applies to non-transient fields.
*/
ALL_NONFINAL_FIELDS_SHOULD_BE_USED,
/**
* Disables the check for reference equality on fields.
*
- *
EqualsVerifier will check if the {@code equals} method calls equals on the object fields
- * of the class under test, instead of the {@code ==} operator, since normally this signifies a
- * mistake (e.g. comparing string fields with {@code ==}).
+ *
+ * EqualsVerifier will check if the {@code equals} method calls equals on the object fields of the class under test,
+ * instead of the {@code ==} operator, since normally this signifies a mistake (e.g. comparing string fields with
+ * {@code ==}).
*
- *
However, sometimes {@code ==} is used intentionally, or the field in question doesn't
- * implement {@code equals} itself, so a call to the {@code equals} method of that field is
- * essentially a reference equality check instead of a value equality check. In these cases,
- * this warning can be suppressed.
+ *
+ * However, sometimes {@code ==} is used intentionally, or the field in question doesn't implement {@code equals}
+ * itself, so a call to the {@code equals} method of that field is essentially a reference equality check instead of
+ * a value equality check. In these cases, this warning can be suppressed.
*/
REFERENCE_EQUALITY,
/**
- * Disables the check, when the {@code equals} method is overridden in the class under test,
- * that an instance of this class should be equal to an identical copy of itself.
+ * Disables the check, when the {@code equals} method is overridden in the class under test, that an instance of
+ * this class should be equal to an identical copy of itself.
*
- *
Normally, it is important that an object be equal to an identical copy of itself: after
- * all, this is the point of overriding {@code equals} in the first place.
+ *
+ * Normally, it is important that an object be equal to an identical copy of itself: after all, this is the point of
+ * overriding {@code equals} in the first place.
*
- *
However, when the class is part of a hierarchy, but should be (pseudo-)singleton, it can
- * be useful to suppress this warning. This can happen in certain implementations of the Null
- * Object Pattern, for example.
+ *
+ * However, when the class is part of a hierarchy, but should be (pseudo-)singleton, it can be useful to suppress
+ * this warning. This can happen in certain implementations of the Null Object Pattern, for example.
*
- *
If this warning is suppressed, and it turns out that an instance of the class under test
- * is equal to an identical copy of itself after all, {@link EqualsVerifier} will fail.
+ *
+ * If this warning is suppressed, and it turns out that an instance of the class under test is equal to an identical
+ * copy of itself after all, {@link EqualsVerifier} will fail.
*/
IDENTICAL_COPY,
/**
- * Disables the check, when the {@code equals} method is overridden in the class under test,
- * that an instance of this class should be equal to an identical copy of itself.
+ * Disables the check, when the {@code equals} method is overridden in the class under test, that an instance of
+ * this class should be equal to an identical copy of itself.
*
- *
Normally, it is important that an object be equal to an identical copy of itself: after
- * all, this is the point of overriding {@code equals} in the first place.
+ *
+ * Normally, it is important that an object be equal to an identical copy of itself: after all, this is the point of
+ * overriding {@code equals} in the first place.
*
- *
However, when the class is a kind of versioned entity and there is an {@code id} field
- * that is zero when the object is new, it is often the case that two new objects are never
- * equal to each other. In these cases, it can be useful to suppress this warning.
+ *
+ * However, when the class is a kind of versioned entity and there is an {@code id} field that is zero when the
+ * object is new, it is often the case that two new objects are never equal to each other. In these cases, it can be
+ * useful to suppress this warning.
*
- *
You cannot use {@link #IDENTICAL_COPY} in these cases, because when the {@code id}s are
- * equal, the objects should be, too, and {@link EqualsVerifier} would fail in this case.
+ *
+ * You cannot use {@link #IDENTICAL_COPY} in these cases, because when the {@code id}s are equal, the objects should
+ * be, too, and {@link EqualsVerifier} would fail in this case.
*
- *
If this warning is suppressed, and it turns out that an instance of the class under test
- * is equal to an identical copy of itself after all, {@link EqualsVerifier} will NOT fail.
+ *
+ * If this warning is suppressed, and it turns out that an instance of the class under test is equal to an identical
+ * copy of itself after all, {@link EqualsVerifier} will NOT fail.
*/
IDENTICAL_COPY_FOR_VERSIONED_ENTITY,
/**
* Disables the check that verifies {@code equals} is actually overridden.
*
- *
Can be used when a whole package of classes is automatically scanned and presented to
- * EqualsVerifier, and one or more of them don't need to override {@code equals}.
+ *
+ * Can be used when a whole package of classes is automatically scanned and presented to EqualsVerifier, and one or
+ * more of them don't need to override {@code equals}.
*/
INHERITED_DIRECTLY_FROM_OBJECT,
/**
* Disables the example check for cached {@code hashCode}.
*
- *
The example check verifies that the cached {@code hashCode} is properly initialized. You
- * can use this, if creating an example object is too cumbersome. In this case, null can be
- * passed as an example.
+ *
+ * The example check verifies that the cached {@code hashCode} is properly initialized. You can use this, if
+ * creating an example object is too cumbersome. In this case, null can be passed as an example.
*
- *
Note that suppressing this warning can be dangerous and should only be done in unusual
- * circumstances.
+ *
+ * Note that suppressing this warning can be dangerous and should only be done in unusual circumstances.
*/
NO_EXAMPLE_FOR_CACHED_HASHCODE,
/**
* Disables checks for non-final fields on which {@code equals} and {@code hashCode} depend.
*
- *
{@link EqualsVerifier}'s standard behaviour is to disallow non-final fields being used in
- * {@code equals} and {@code hashCode} methods, since classes that depend on non-final fields in
- * these methods cannot reliably be used in collections.
+ *
+ * {@link EqualsVerifier}'s standard behaviour is to disallow non-final fields being used in {@code equals} and
+ * {@code hashCode} methods, since classes that depend on non-final fields in these methods cannot reliably be used
+ * in collections.
*
- *
However, sometimes an external library requires that fields be non-final. An example of
- * this are Java Beans. In such a case, suppress this warning to prevent {@link EqualsVerifier}
- * from checking for non-final fields.
+ *
+ * However, sometimes an external library requires that fields be non-final. An example of this are Java Beans. In
+ * such a case, suppress this warning to prevent {@link EqualsVerifier} from checking for non-final fields.
*/
NONFINAL_FIELDS,
/**
- * Disables checks for {@link NullPointerException} within {@code equals}, {@code hashCode} and
- * {@code toString} methods.
+ * Disables checks for {@link NullPointerException} within {@code equals}, {@code hashCode} and {@code toString}
+ * methods.
*
- *
Sometimes the constructor of a class makes sure no field can be null. If this is the case,
- * and if the fields cannot be made null later in the lifecycle of the class by setters or other
- * methods, suppress this warning to disable the check for {@link NullPointerException}.
+ *
+ * Sometimes the constructor of a class makes sure no field can be null. If this is the case, and if the fields
+ * cannot be made null later in the lifecycle of the class by setters or other methods, suppress this warning to
+ * disable the check for {@link NullPointerException}.
*/
NULL_FIELDS,
@@ -122,88 +133,93 @@ public enum Warning {
* Disables the check that all fields used in {@code equals} must also be used in {@code
* hashCode}.
*
- *
This is useful when bringing legacy systems under test, where you don't want to change the
- * existing {@code hashCode} behaviour but you do want to use EqualsVerifier.
+ *
+ * This is useful when bringing legacy systems under test, where you don't want to change the existing
+ * {@code hashCode} behaviour but you do want to use EqualsVerifier.
*
- *
Note that {@code hashCode}s with higher distributions give better performance when used in
- * collections such as {@link java.util.HashMap}. Therefore, if possible, you should use all
- * fields that are used in {@code equals}, in {@code hashCode} as well.
+ *
+ * Note that {@code hashCode}s with higher distributions give better performance when used in collections such as
+ * {@link java.util.HashMap}. Therefore, if possible, you should use all fields that are used in {@code equals}, in
+ * {@code hashCode} as well.
*/
STRICT_HASHCODE,
/**
* Disables some of the stricter inheritance tests.
*
- *
{@link EqualsVerifier}'s standard behaviour, if T is not final and neither are its {@code
- * equals} and {@code hashCode} methods, is to require a reference to a subclass of T for which
- * no instance can be equal to any instance of T, to make sure that subclasses that can redefine
- * {@code equals} or {@code hashCode} don't break the contract; or it asks to call the {@code
- * usingGetClass} method if T uses {@code getClass()} instead of {@code instanceof} in its
- * {@code equals} method.
+ *
+ * {@link EqualsVerifier}'s standard behaviour, if T is not final and neither are its {@code
+ * equals} and {@code hashCode} methods, is to require a reference to a subclass of T for which no instance can be
+ * equal to any instance of T, to make sure that subclasses that can redefine {@code equals} or {@code hashCode}
+ * don't break the contract; or it asks to call the {@code
+ * usingGetClass} method if T uses {@code getClass()} instead of {@code instanceof} in its {@code equals} method.
*
- *
Some may find that too strict for their liking; suppressing this warning disables that
- * test.
+ *
+ * Some may find that too strict for their liking; suppressing this warning disables that test.
*
* @see nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi#withRedefinedSubclass(Class)
*/
STRICT_INHERITANCE,
/**
- * Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities
- * may not be used in the {@code equals} contract.
+ * Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in
+ * the {@code equals} contract.
*
- *
When this warning is suppressed, the fields marked with @Id or @EmbeddedId will become the
- * entity's surrogate key. Only these fields can now be part of the {@code equals} contract; all
- * other fields may no longer be used in {@code equals}.
+ *
+ * When this warning is suppressed, the fields marked with @Id or @EmbeddedId will become the entity's surrogate
+ * key. Only these fields can now be part of the {@code equals} contract; all other fields may no longer be used in
+ * {@code equals}.
*/
SURROGATE_KEY,
/**
- * Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities
- * may not be used in the {@code equals} contract.
+ * Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in
+ * the {@code equals} contract.
*
- *
When this warning is suppressed, all fields will become part of the entity's key, and
- * EqualsVerifier will operate as if the entity were a normal class.
+ *
+ * When this warning is suppressed, all fields will become part of the entity's key, and EqualsVerifier will operate
+ * as if the entity were a normal class.
*/
SURROGATE_OR_BUSINESS_KEY,
/**
- * Disables the check that collection fields in JPA, or @Basic fields marked with
- * FetchType.LAZY, should be accessed through their getter methods in {@code equals} and
- * {@code hashCode} methods.
+ * Disables the check that collection fields in JPA, or @Basic fields marked with FetchType.LAZY, should be accessed
+ * through their getter methods in {@code equals} and {@code hashCode} methods.
*
- *
Normally, it is necessary to go through the getter for these fields, because their
- * content may not be materialized in some instances. Calling the getter will materialize them,
- * but referencing the field directly will not. This can lead to situations where the
- * {@code equals} method of objects that should be equal to each other returns false, because
- * one instance has the content materialized and the other does not.
+ *
+ * Normally, it is necessary to go through the getter for these fields, because their content may not be
+ * materialized in some instances. Calling the getter will materialize them, but referencing the field directly will
+ * not. This can lead to situations where the {@code equals} method of objects that should be equal to each other
+ * returns false, because one instance has the content materialized and the other does not.
*/
JPA_GETTER,
/**
* Disables the check that transient fields not be part of the {@code equals} contract.
*
- *
{@link EqualsVerifier}'s standard behaviour is to disallow transient fields being used in
- * {@code equals} and {@code hashCode} methods, since these fields may not be restored to their
- * original state after deserialization, which would break {@code equals}.
+ *
+ * {@link EqualsVerifier}'s standard behaviour is to disallow transient fields being used in {@code equals} and
+ * {@code hashCode} methods, since these fields may not be restored to their original state after deserialization,
+ * which would break {@code equals}.
*
- *
If measures are taken that this will never happen, this warning can be suppressed to
- * disable {@link EqualsVerifier}'s transience test.
+ *
+ * If measures are taken that this will never happen, this warning can be suppressed to disable
+ * {@link EqualsVerifier}'s transience test.
*/
TRANSIENT_FIELDS,
/**
- * Disables the check that equality of {@code BigDecimal} fields is implemented using
- * {@code compareTo} rather than {@code equals}.
+ * Disables the check that equality of {@code BigDecimal} fields is implemented using {@code compareTo} rather than
+ * {@code equals}.
*
- *
{@code BigDecimal} objects that are equal using {@code compareTo} are not necessarily
- * equal using {@code equals}, for example the values of {@literal 1} and {@literal 1.0}.
- * For variants of the same value to be considered equal, classes with {@code BigDecimal}
- * fields should use {@code compareTo} to check equality of non-null {@code BigDecimal}
- * references and produce the same hashcode for all equal variants.
+ *
+ * {@code BigDecimal} objects that are equal using {@code compareTo} are not necessarily equal using {@code equals},
+ * for example the values of {@literal 1} and {@literal 1.0}. For variants of the same value to be considered equal,
+ * classes with {@code BigDecimal} fields should use {@code compareTo} to check equality of non-null
+ * {@code BigDecimal} references and produce the same hashcode for all equal variants.
*
- *
{@code EqualsVerifier} checks for this by default but it can be disabled by suppressing
- * this warning.
+ *
+ * {@code EqualsVerifier} checks for this by default but it can be disabled by suppressing this warning.
*/
BIGDECIMAL_EQUALITY,
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/EqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/EqualsVerifierApi.java
index fbb3e9491..6fc65128f 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/EqualsVerifierApi.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/EqualsVerifierApi.java
@@ -1,6 +1,7 @@
package nl.jqno.equalsverifier.api;
import java.util.function.Function;
+
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Func.Func1;
import nl.jqno.equalsverifier.Func.Func2;
@@ -13,8 +14,7 @@
*/
public interface EqualsVerifierApi {
/**
- * Suppresses warnings given by {@code EqualsVerifier}. See {@link Warning} to see what warnings
- * can be suppressed.
+ * Suppresses warnings given by {@code EqualsVerifier}. See {@link Warning} to see what warnings can be suppressed.
*
* @param warnings A list of warnings to suppress in {@code EqualsVerifier}.
* @return {@code this}, for easy method chaining.
@@ -22,49 +22,46 @@ public interface EqualsVerifierApi {
EqualsVerifierApi suppress(Warning... warnings);
/**
- * Adds prefabricated values for instance fields of classes that EqualsVerifier cannot
- * instantiate by itself.
+ * Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself.
*
- * @param The class of the prefabricated values.
+ * @param The class of the prefabricated values.
* @param otherType The class of the prefabricated values.
- * @param red An instance of {@code S}.
- * @param blue Another instance of {@code S}, not equal to {@code red}.
+ * @param red An instance of {@code S}.
+ * @param blue Another instance of {@code S}, not equal to {@code red}.
* @return {@code this}, for easy method chaining.
- * @throws NullPointerException If either {@code otherType}, {@code red}, or {@code blue} is
- * null.
+ * @throws NullPointerException If either {@code otherType}, {@code red}, or {@code blue} is null.
* @throws IllegalArgumentException If {@code red} equals {@code blue}.
*/
EqualsVerifierApi withPrefabValues(Class otherType, S red, S blue);
/**
- * Adds a factory to generate prefabricated values for instance fields of classes with 1 generic
- * type parameter that EqualsVerifier cannot instantiate by itself.
+ * Adds a factory to generate prefabricated values for instance fields of classes with 1 generic type parameter that
+ * EqualsVerifier cannot instantiate by itself.
*
- * @param The class of the prefabricated values.
+ * @param The class of the prefabricated values.
* @param otherType The class of the prefabricated values.
- * @param factory A factory to generate an instance of {@code S}, given a value of its generic
- * type parameter.
+ * @param factory A factory to generate an instance of {@code S}, given a value of its generic type parameter.
* @return {@code this}, for easy method chaining.
* @throws NullPointerException if either {@code otherType} or {@code factory} is null.
*/
EqualsVerifierApi withGenericPrefabValues(Class otherType, Func1, S> factory);
/**
- * Adds a factory to generate prefabricated values for instance fields of classes with 2 generic
- * type parameters that EqualsVerifier cannot instantiate by itself.
+ * Adds a factory to generate prefabricated values for instance fields of classes with 2 generic type parameters
+ * that EqualsVerifier cannot instantiate by itself.
*
- * @param The class of the prefabricated values.
+ * @param The class of the prefabricated values.
* @param otherType The class of the prefabricated values.
- * @param factory A factory to generate an instance of {@code S}, given a value of each of its
- * generic type parameters.
+ * @param factory A factory to generate an instance of {@code S}, given a value of each of its generic type
+ * parameters.
* @return {@code this}, for easy method chaining.
* @throws NullPointerException if either {@code otherType} or {@code factory} is null.
*/
EqualsVerifierApi withGenericPrefabValues(Class otherType, Func2, ?, S> factory);
/**
- * Signals that {@code getClass} is used in the implementation of the {@code equals} method,
- * instead of an {@code instanceof} check.
+ * Signals that {@code getClass} is used in the implementation of the {@code equals} method, instead of an
+ * {@code instanceof} check.
*
* @return {@code this}, for easy method chaining.
* @see Warning#STRICT_INHERITANCE
@@ -74,8 +71,8 @@ public interface EqualsVerifierApi {
/**
* Determines how a getter name can be derived from a field name.
*
- * The default behavior is to uppercase the field's first letter and prepend 'get'. For
- * instance, a field name 'employee' would correspond to getter name 'getEmployee'.
+ * The default behavior is to uppercase the field's first letter and prepend 'get'. For instance, a field name
+ * 'employee' would correspond to getter name 'getEmployee'.
*
* This method can be used if your project has a different naming convention.
*
@@ -85,9 +82,9 @@ public interface EqualsVerifierApi {
EqualsVerifierApi withFieldnameToGetterConverter(Function converter);
/**
- * Signals that all internal caches need to be reset. This is useful when the test framework
- * uses multiple ClassLoaders to run tests, causing {@link java.lang.Class} instances
- * that would normally be equal, to be unequal, because their ClassLoaders don't match.
+ * Signals that all internal caches need to be reset. This is useful when the test framework uses multiple
+ * ClassLoaders to run tests, causing {@link java.lang.Class} instances that would normally be equal, to be unequal,
+ * because their ClassLoaders don't match.
*
* @return {@code this}, for easy method chaining.
* @deprecated No longer needed; this happens automatically.
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/MultipleTypeEqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/MultipleTypeEqualsVerifierApi.java
index ecb285619..dcd593684 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/MultipleTypeEqualsVerifierApi.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/MultipleTypeEqualsVerifierApi.java
@@ -5,6 +5,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+
import nl.jqno.equalsverifier.ConfiguredEqualsVerifier;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.EqualsVerifierReport;
@@ -45,20 +46,14 @@ public MultipleTypeEqualsVerifierApi withPrefabValues(Class otherType, S
/** {@inheritDoc} */
@Override
- public MultipleTypeEqualsVerifierApi withGenericPrefabValues(
- Class otherType,
- Func1, S> factory
- ) {
+ public MultipleTypeEqualsVerifierApi withGenericPrefabValues(Class otherType, Func1, S> factory) {
ev.withGenericPrefabValues(otherType, factory);
return this;
}
/** {@inheritDoc} */
@Override
- public MultipleTypeEqualsVerifierApi withGenericPrefabValues(
- Class otherType,
- Func2, ?, S> factory
- ) {
+ public MultipleTypeEqualsVerifierApi withGenericPrefabValues(Class otherType, Func2, ?, S> factory) {
ev.withGenericPrefabValues(otherType, factory);
return this;
}
@@ -72,15 +67,14 @@ public MultipleTypeEqualsVerifierApi usingGetClass() {
/** {@inheritDoc} */
@Override
- public MultipleTypeEqualsVerifierApi withFieldnameToGetterConverter(
- Function converter
- ) {
+ public MultipleTypeEqualsVerifierApi withFieldnameToGetterConverter(Function converter) {
ev.withFieldnameToGetterConverter(converter);
return this;
}
/**
* {@inheritDoc}
+ *
* @deprecated No longer needed; this happens automatically.
*/
@Deprecated
@@ -105,15 +99,11 @@ public MultipleTypeEqualsVerifierApi except(Class> type, Class>... more) {
/**
* Removes all types matching the given Predicate.
*
- * @param exclusionPredicate A Predicate matching classes to remove from the list of types to
- * verify.
+ * @param exclusionPredicate A Predicate matching classes to remove from the list of types to verify.
* @return {@code this}, for easy method chaining.
*/
public MultipleTypeEqualsVerifierApi except(Predicate> exclusionPredicate) {
- List> typesToRemove = types
- .stream()
- .filter(exclusionPredicate)
- .collect(Collectors.toList());
+ List> typesToRemove = types.stream().filter(exclusionPredicate).collect(Collectors.toList());
removeTypes(typesToRemove);
return this;
}
@@ -124,42 +114,36 @@ private void removeTypes(List> typesToRemove) {
}
/**
- * Performs the verification of the contracts for {@code equals} and {@code hashCode} and throws
- * an {@link AssertionError} if there is a problem.
+ * Performs the verification of the contracts for {@code equals} and {@code hashCode} and throws an
+ * {@link AssertionError} if there is a problem.
*
- * @throws AssertionError If one of the contracts is not met, or if {@link EqualsVerifier}'s
- * preconditions do not hold.
+ * @throws AssertionError If one of the contracts is not met, or if {@link EqualsVerifier}'s preconditions do not
+ * hold.
*/
public void verify() {
- List failures = report()
- .stream()
- .filter(r -> !r.isSuccessful())
- .collect(Collectors.toList());
+ List failures =
+ report().stream().filter(r -> !r.isSuccessful()).collect(Collectors.toList());
if (failures.isEmpty()) {
return;
}
String messages = Formatter
- .of(
- "EqualsVerifier found a problem in %% %%.\n---\n%%\n---\n%%\n---\n%%",
- failures.size(),
- failures.size() == 1 ? "class" : "classes",
- failures
- .stream()
- .map(r -> "* " + r.getType().getName())
- .collect(Collectors.joining("\n")),
- failures.stream().map(r -> r.getMessage()).collect(Collectors.joining("\n---\n")),
- ErrorMessage.suffix()
- )
- .format();
+ .of(
+ "EqualsVerifier found a problem in %% %%.\n---\n%%\n---\n%%\n---\n%%",
+ failures.size(),
+ failures.size() == 1 ? "class" : "classes",
+ failures.stream().map(r -> "* " + r.getType().getName()).collect(Collectors.joining("\n")),
+ failures.stream().map(r -> r.getMessage()).collect(Collectors.joining("\n---\n")),
+ ErrorMessage.suffix())
+ .format();
throw new AssertionError(messages);
}
/**
- * Performs the verifications of the contracts for {@code equals} and {@code hashCode} and
- * returns a List of {@link EqualsVerifierReport} with the results of the verifications.
+ * Performs the verifications of the contracts for {@code equals} and {@code hashCode} and returns a List of
+ * {@link EqualsVerifierReport} with the results of the verifications.
*
- * @return A List of {@link EqualsVerifierReport} that indicates whether the contracts are met
- * and whether {@link EqualsVerifier}'s preconditions hold.
+ * @return A List of {@link EqualsVerifierReport} that indicates whether the contracts are met and whether
+ * {@link EqualsVerifier}'s preconditions hold.
*/
public List report() {
return types.stream().map(t -> ev.forClass(t).report(false)).collect(Collectors.toList());
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/RelaxedEqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/RelaxedEqualsVerifierApi.java
index c52eac1b8..9eff0f600 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/RelaxedEqualsVerifierApi.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/RelaxedEqualsVerifierApi.java
@@ -4,14 +4,15 @@
import java.util.Collections;
import java.util.List;
+
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.util.Validations;
/**
- * API class for {@link EqualsVerifier#forRelaxedEqualExamples(Object, Object, Object...)}. Its
- * purpose is to make sure, at compile time, that a list of unequal examples is given, as well as
- * the list of equal examples that are supplied to the aforementioned method.
+ * API class for {@link EqualsVerifier#forRelaxedEqualExamples(Object, Object, Object...)}. Its purpose is to make sure,
+ * at compile time, that a list of unequal examples is given, as well as the list of equal examples that are supplied to
+ * the aforementioned method.
*/
public class RelaxedEqualsVerifierApi {
@@ -21,7 +22,7 @@ public class RelaxedEqualsVerifierApi {
/**
* Constructor.
*
- * @param type The class for which the {@code equals} method should be tested.
+ * @param type The class for which the {@code equals} method should be tested.
* @param examples A list of example instances that are equal but not identical to one another.
*/
public RelaxedEqualsVerifierApi(Class type, List examples) {
@@ -41,13 +42,12 @@ public SingleTypeEqualsVerifierApi andUnequalExample(T example) {
}
/**
- * Asks for a list of unequal instances of T and subsequently returns a fully constructed
- * instance of {@link EqualsVerifier}.
+ * Asks for a list of unequal instances of T and subsequently returns a fully constructed instance of
+ * {@link EqualsVerifier}.
*
* @param first An instance of T that is unequal to the previously supplied equal examples.
- * @param more More instances of T, all of which are unequal to one another, to {@code first},
- * and to the previously supplied equal examples. May also contain instances of subclasses
- * of T.
+ * @param more More instances of T, all of which are unequal to one another, to {@code first}, and to the
+ * previously supplied equal examples. May also contain instances of subclasses of T.
* @return An instance of {@link EqualsVerifier}.
*/
@SafeVarargs
@@ -55,6 +55,6 @@ public final SingleTypeEqualsVerifierApi andUnequalExamples(T first, T... mor
List unequalExamples = buildListOfAtLeastOne(first, more);
Validations.validateUnequalExamples(unequalExamples, equalExamples);
return new SingleTypeEqualsVerifierApi<>(type, equalExamples, unequalExamples)
- .suppress(Warning.ALL_FIELDS_SHOULD_BE_USED);
+ .suppress(Warning.ALL_FIELDS_SHOULD_BE_USED);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java
index e87acdac8..0967c5d1b 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java
@@ -2,6 +2,7 @@
import java.util.*;
import java.util.function.Function;
+
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.EqualsVerifierReport;
import nl.jqno.equalsverifier.Func.Func1;
@@ -33,8 +34,7 @@ public class SingleTypeEqualsVerifierApi implements EqualsVerifierApi {
private Class extends T> redefinedSubclass = null;
private FactoryCache factoryCache = new FactoryCache();
private FieldCache fieldCache = new FieldCache();
- private CachedHashCodeInitializer cachedHashCodeInitializer =
- CachedHashCodeInitializer.passthrough();
+ private CachedHashCodeInitializer cachedHashCodeInitializer = CachedHashCodeInitializer.passthrough();
private Function fieldnameToGetter = null;
private Set allExcludedFields = new HashSet<>();
private Set allIncludedFields = new HashSet<>();
@@ -56,7 +56,7 @@ public SingleTypeEqualsVerifierApi(Class type) {
/**
* Constructor.
*
- * @param type The class for which the {@code equals} method should be tested.
+ * @param type The class for which the {@code equals} method should be tested.
* @param objenesis To instantiate non-record classes.
*/
public SingleTypeEqualsVerifierApi(Class type, Objenesis objenesis) {
@@ -68,22 +68,21 @@ public SingleTypeEqualsVerifierApi(Class type, Objenesis objenesis) {
/**
* Constructor.
*
- * @param type The class for which the {@code equals} method should be tested.
+ * @param type The class for which the {@code equals} method should be tested.
* @param warningsToSuppress A list of warnings to suppress in {@code EqualsVerifier}.
- * @param factoryCache Factories that can be used to create values.
- * @param objenesis To instantiate non-record classes.
- * @param usingGetClass Whether {@code getClass} is used in the implementation of the {@code
- * equals} method, instead of an {@code instanceof} check.
- * @param converter A function that converts from field name to getter name.
+ * @param factoryCache Factories that can be used to create values.
+ * @param objenesis To instantiate non-record classes.
+ * @param usingGetClass Whether {@code getClass} is used in the implementation of the {@code
+ * equals} method, instead of an {@code instanceof} check.
+ * @param converter A function that converts from field name to getter name.
*/
public SingleTypeEqualsVerifierApi(
- Class type,
- EnumSet warningsToSuppress,
- FactoryCache factoryCache,
- Objenesis objenesis,
- boolean usingGetClass,
- Function converter
- ) {
+ Class type,
+ EnumSet warningsToSuppress,
+ FactoryCache factoryCache,
+ Objenesis objenesis,
+ boolean usingGetClass,
+ Function converter) {
this(type, objenesis);
this.warningsToSuppress = EnumSet.copyOf(warningsToSuppress);
this.factoryCache = this.factoryCache.merge(factoryCache);
@@ -92,14 +91,9 @@ public SingleTypeEqualsVerifierApi(
}
/**
- * Constructor, only to be called by {@link RelaxedEqualsVerifierApi#andUnequalExamples(Object,
- * Object[])}.
+ * Constructor, only to be called by {@link RelaxedEqualsVerifierApi#andUnequalExamples(Object, Object[])}.
*/
- /* package protected */SingleTypeEqualsVerifierApi(
- Class type,
- List equalExamples,
- List unequalExamples
- ) {
+ /* package protected */ SingleTypeEqualsVerifierApi(Class type, List equalExamples, List unequalExamples) {
this(type, new ObjenesisStd());
this.equalExamples = equalExamples;
this.unequalExamples = unequalExamples;
@@ -110,11 +104,7 @@ public SingleTypeEqualsVerifierApi(
public SingleTypeEqualsVerifierApi suppress(Warning... warnings) {
Collections.addAll(warningsToSuppress, warnings);
Validations.validateWarnings(warningsToSuppress);
- Validations.validateWarningsAndFields(
- warningsToSuppress,
- allIncludedFields,
- allExcludedFields
- );
+ Validations.validateWarningsAndFields(warningsToSuppress, allIncludedFields, allExcludedFields);
Validations.validateNonnullFields(nonnullFields, warningsToSuppress);
return this;
}
@@ -127,23 +117,19 @@ public SingleTypeEqualsVerifierApi withPrefabValues(Class 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.
+ * Adds prefabricated values for instance fields with a given name (and only the fields with the given name) that
+ * EqualsVerifier cannot instantiate by itself.
*
- * @param The class of the prefabricated values.
+ * @param 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}.
- * @param blue Another instance of {@code S}, not equal to {@code red}.
+ * @param red An instance of {@code S}.
+ * @param blue Another instance of {@code S}, not equal to {@code red}.
* @return {@code this}, for easy method chaining.
- * @throws NullPointerException If {@code red} or {@code blue} is null, or if the named field
- * does not exist in the class.
+ * @throws NullPointerException If {@code red} or {@code blue} is null, or if the named field does not exist in
+ * the class.
* @throws IllegalArgumentException If {@code red} equals {@code blue}.
*/
- public SingleTypeEqualsVerifierApi withPrefabValuesForField(
- String fieldName,
- S red,
- S blue
- ) {
+ public SingleTypeEqualsVerifierApi withPrefabValuesForField(String fieldName, S red, S blue) {
PrefabValuesApi.addPrefabValuesForField(fieldCache, objenesis, type, fieldName, red, blue);
withNonnullFields(fieldName);
return this;
@@ -151,20 +137,14 @@ public SingleTypeEqualsVerifierApi withPrefabValuesForField(
/** {@inheritDoc} */
@Override
- public SingleTypeEqualsVerifierApi withGenericPrefabValues(
- Class otherType,
- Func1, S> factory
- ) {
+ public SingleTypeEqualsVerifierApi withGenericPrefabValues(Class otherType, Func1, S> factory) {
PrefabValuesApi.addGenericPrefabValues(factoryCache, otherType, factory);
return this;
}
/** {@inheritDoc} */
@Override
- public SingleTypeEqualsVerifierApi withGenericPrefabValues(
- Class otherType,
- Func2, ?, S> factory
- ) {
+ public SingleTypeEqualsVerifierApi withGenericPrefabValues(Class otherType, Func2, ?, S> factory) {
PrefabValuesApi.addGenericPrefabValues(factoryCache, otherType, factory);
return this;
}
@@ -178,9 +158,7 @@ public SingleTypeEqualsVerifierApi usingGetClass() {
/** {@inheritDoc} */
@Override
- public SingleTypeEqualsVerifierApi withFieldnameToGetterConverter(
- Function converter
- ) {
+ public SingleTypeEqualsVerifierApi withFieldnameToGetterConverter(Function converter) {
this.fieldnameToGetter = converter;
return this;
}
@@ -190,7 +168,8 @@ public SingleTypeEqualsVerifierApi withFieldnameToGetterConverter(
* EqualsVerifier} will not fail if one of these fields does not affect the outcome of {@code
* equals}, but it will fail if one of these fields does affect the outcome of {@code equals}.
*
- * Note that these fields will still be used to test for null-ness, among other things.
+ *
+ * Note that these fields will still be used to test for null-ness, among other things.
*
* @param fields Fields that should be ignored.
* @return {@code this}, for easy method chaining.
@@ -200,10 +179,9 @@ public SingleTypeEqualsVerifierApi withIgnoredFields(String... fields) {
}
/**
- * Signals that all given fields, and only the given fields, are relevant for the
- * {@code equals} contract. {@code EqualsVerifier} will fail if one of these fields does not
- * affect the outcome of {@code equals}, and it will fail if a field that isn't listed here,
- * does affect the outcome of {@code equals}.
+ * Signals that all given fields, and only the given fields, are relevant for the {@code equals} contract.
+ * {@code EqualsVerifier} will fail if one of these fields does not affect the outcome of {@code equals}, and it
+ * will fail if a field that isn't listed here, does affect the outcome of {@code equals}.
*
* @param fields Fields that should be ignored.
* @return {@code this}, for easy method chaining.
@@ -213,27 +191,23 @@ public SingleTypeEqualsVerifierApi withOnlyTheseFields(String... fields) {
}
private SingleTypeEqualsVerifierApi withFieldsAddedAndValidated(
- Set collection,
- List specifiedFields
- ) {
+ Set collection,
+ List specifiedFields) {
collection.addAll(specifiedFields);
Validations.validateFields(allIncludedFields, allExcludedFields);
Validations.validateFieldNamesExist(type, specifiedFields, actualFields);
- Validations.validateWarningsAndFields(
- warningsToSuppress,
- allIncludedFields,
- allExcludedFields
- );
+ Validations.validateWarningsAndFields(warningsToSuppress, allIncludedFields, allExcludedFields);
return this;
}
/**
- * Signals that all given fields can never be null, and {@code EqualsVerifier} therefore doesn't
- * have to verify that proper null checks are in place for these fields.
+ * Signals that all given fields can never be null, and {@code EqualsVerifier} therefore doesn't have to verify that
+ * proper null checks are in place for these fields.
*
- * This can be used instead of {link #suppress(Warning...)}, which provides the same
- * behaviour for all fields, when only some fields are never null but others are.
+ *
+ * This can be used instead of {link #suppress(Warning...)}, which provides the same behaviour for all fields, when
+ * only some fields are never null but others are.
*
* @param fields Fields that can never be null.
* @return {@code this}, for easy method chaining.
@@ -249,8 +223,9 @@ public SingleTypeEqualsVerifierApi withNonnullFields(String... fields) {
/**
* Signals that all given annotations are to be ignored by EqualsVerifier.
*
- * For instance, EqualsVerifier normally doesn't perform null verifications on fields marked
- * with an {@code @Nonnull} annotation. However, if this method is called with a {@code
+ *
+ * For instance, EqualsVerifier normally doesn't perform null verifications on fields marked with an
+ * {@code @Nonnull} annotation. However, if this method is called with a {@code
* Nonnull.class} parameter, the null verifications will be performed after all.
*
* @param annotations Annotations to ignore.
@@ -265,12 +240,11 @@ public SingleTypeEqualsVerifierApi withIgnoredAnnotations(Class>... annotat
}
/**
- * Signals that T is part of an inheritance hierarchy where {@code equals} is overridden. Call
- * this method if T has overridden {@code equals} and {@code hashCode}, and one or more of T's
- * superclasses have as well.
+ * Signals that T is part of an inheritance hierarchy where {@code equals} is overridden. Call this method if T has
+ * overridden {@code equals} and {@code hashCode}, and one or more of T's superclasses have as well.
*
- * T itself does not necessarily have to have subclasses that redefine {@code equals} and
- * {@code hashCode}.
+ *
+ * T itself does not necessarily have to have subclasses that redefine {@code equals} and {@code hashCode}.
*
* @return {@code this}, for easy method chaining.
*/
@@ -280,11 +254,12 @@ public SingleTypeEqualsVerifierApi withRedefinedSuperclass() {
}
/**
- * Supplies a reference to a subclass of T in which {@code equals} is overridden. Calling this
- * method is mandatory if {@code equals} is not final and a strong verification is performed.
+ * Supplies a reference to a subclass of T in which {@code equals} is overridden. Calling this method is mandatory
+ * if {@code equals} is not final and a strong verification is performed.
*
- * Note that, for each subclass that overrides {@code equals}, {@link EqualsVerifier} should
- * be used as well to verify its adherence to the contracts.
+ *
+ * Note that, for each subclass that overrides {@code equals}, {@link EqualsVerifier} should be used as well to
+ * verify its adherence to the contracts.
*
* @param subclass A subclass of T for which no instance can be equal to any instance of T.
* @return {@code this}, for easy method chaining.
@@ -299,48 +274,43 @@ public SingleTypeEqualsVerifierApi withRedefinedSubclass(Class extends T> s
* Signals that T caches its hashCode, instead of re-calculating it each time the {@code
* hashCode()} method is called.
*
- * There are 3 conditions to verify cached hashCodes:
+ *
+ * There are 3 conditions to verify cached hashCodes:
*
- *
First, the class under test must have a private int field that contains the cached
- * hashCode.
+ *
+ * First, the class under test must have a private int field that contains the cached hashCode.
*
- *
Second, the class under test must have a private method that calculates the hashCode. The
- * method must return an int and may not take any parameters. It should be used by the
- * constructor or the hashCode method of the class under test to initialize the cached hashCode.
- * This may lead to slightly awkward production code, but unfortunately, it is necessary for
- * EqualsVerifier to verify that the hashCode is correct.
+ *
+ * Second, the class under test must have a private method that calculates the hashCode. The method must return an
+ * int and may not take any parameters. It should be used by the constructor or the hashCode method of the class
+ * under test to initialize the cached hashCode. This may lead to slightly awkward production code, but
+ * unfortunately, it is necessary for EqualsVerifier to verify that the hashCode is correct.
*
- *
Finally, only immutable objects can be verified. In other words, {@code
+ *
+ * Finally, only immutable objects can be verified. In other words, {@code
* withCachedHashCode} can not be used when {@link Warning#NONFINAL_FIELDS} is suppressed.
*
- * @param cachedHashCodeField The name of the field which stores the cached hash code.
- * @param calculateHashCodeMethod The name of the method which recomputes the hash code. It
- * should return an int and take no parameters.
- * @param example An instance of the class under test, to verify that the hashCode has been
- * initialized properly.
+ * @param cachedHashCodeField The name of the field which stores the cached hash code.
+ * @param calculateHashCodeMethod The name of the method which recomputes the hash code. It should return an int and
+ * take no parameters.
+ * @param example An instance of the class under test, to verify that the hashCode has been
+ * initialized properly.
* @return {@code this}, for easy method chaining.
*/
public SingleTypeEqualsVerifierApi withCachedHashCode(
- String cachedHashCodeField,
- String calculateHashCodeMethod,
- T example
- ) {
+ String cachedHashCodeField,
+ String calculateHashCodeMethod,
+ T example) {
cachedHashCodeInitializer =
- new CachedHashCodeInitializer<>(
- type,
- cachedHashCodeField,
- calculateHashCodeMethod,
- example
- );
+ new CachedHashCodeInitializer<>(type, cachedHashCodeField, calculateHashCodeMethod, example);
return this;
}
/**
- * Signals that T uses Lombok to cache its hashCode, instead of re-calculating it each time the
- * {@code hashCode()} method is called.
+ * Signals that T uses Lombok to cache its hashCode, instead of re-calculating it each time the {@code hashCode()}
+ * method is called.
*
- * @param example An instance of the class under test, to verify that the hashCode has been
- * initialized properly.
+ * @param example An instance of the class under test, to verify that the hashCode has been initialized properly.
* @return {@code this}, for easy method chaining.
* @see #withCachedHashCode(String, String, Object)
*/
@@ -351,6 +321,7 @@ public SingleTypeEqualsVerifierApi withLombokCachedHashCode(T example) {
/**
* {@inheritDoc}
+ *
* @deprecated No longer needed; this happens automatically.
*/
@Deprecated
@@ -360,65 +331,59 @@ public SingleTypeEqualsVerifierApi withResetCaches() {
}
/**
- * Performs the verification of the contracts for {@code equals} and {@code hashCode} and throws
- * an {@link AssertionError} if there is a problem.
+ * Performs the verification of the contracts for {@code equals} and {@code hashCode} and throws an
+ * {@link AssertionError} if there is a problem.
*
- * @throws AssertionError If the contract is not met, or if {@link EqualsVerifier}'s
- * preconditions do not hold.
+ * @throws AssertionError If the contract is not met, or if {@link EqualsVerifier}'s preconditions do not hold.
*/
public void verify() {
try {
performVerification();
- } catch (MessagingException e) {
+ }
+ catch (MessagingException e) {
throw new AssertionError(buildErrorMessage(e.getDescription(), true), e);
- } catch (Throwable e) {
+ }
+ catch (Throwable e) {
throw new AssertionError(buildErrorMessage(e.getMessage(), true), e);
}
}
/**
- * Performs the verification of the contracts for {@code equals} and {@code hashCode} and
- * returns an {@link EqualsVerifierReport} with the results of the verification.
+ * Performs the verification of the contracts for {@code equals} and {@code hashCode} and returns an
+ * {@link EqualsVerifierReport} with the results of the verification.
*
- * @return An {@link EqualsVerifierReport} that indicates whether the contract is met and
- * whether {@link EqualsVerifier}'s preconditions hold.
+ * @return An {@link EqualsVerifierReport} that indicates whether the contract is met and whether
+ * {@link EqualsVerifier}'s preconditions hold.
*/
public EqualsVerifierReport report() {
return report(true);
}
/**
- * Performs the verification of the contracts for {@code equals} and {@code hashCode} and
- * returns an {@link EqualsVerifierReport} with the results of the verification.
+ * Performs the verification of the contracts for {@code equals} and {@code hashCode} and returns an
+ * {@link EqualsVerifierReport} with the results of the verification.
*
* @param showUrl Whether or not to show the url at the end of the error message.
- * @return An {@link EqualsVerifierReport} that indicates whether the contract is met and
- * whether {@link EqualsVerifier}'s preconditions hold.
+ * @return An {@link EqualsVerifierReport} that indicates whether the contract is met and whether
+ * {@link EqualsVerifier}'s preconditions hold.
*/
public EqualsVerifierReport report(boolean showUrl) {
try {
performVerification();
return EqualsVerifierReport.success(type);
- } catch (MessagingException e) {
- return EqualsVerifierReport.failure(
- type,
- buildErrorMessage(e.getDescription(), showUrl),
- e
- );
- } catch (Throwable e) {
- return EqualsVerifierReport.failure(
- type,
- buildErrorMessage(e.getMessage(), showUrl),
- e
- );
+ }
+ catch (MessagingException e) {
+ return EqualsVerifierReport.failure(type, buildErrorMessage(e.getDescription(), showUrl), e);
+ }
+ catch (Throwable e) {
+ return EqualsVerifierReport.failure(type, buildErrorMessage(e.getMessage(), showUrl), e);
}
}
private String buildErrorMessage(String description, boolean showUrl) {
String message = description == null ? "" : description;
- String result = Formatter
- .of("EqualsVerifier found a problem in class %%.\n-> %%", type.getName(), message)
- .format();
+ String result =
+ Formatter.of("EqualsVerifier found a problem in class %%.\n-> %%", type.getName(), message).format();
if (showUrl) {
result += "\n\n" + ErrorMessage.suffix();
}
@@ -433,47 +398,42 @@ private void performVerification() {
Configuration config = buildConfig();
Context context = new Context<>(config, factoryCache, fieldCache, objenesis);
- Validations.validateProcessedAnnotations(
- type,
- config.getAnnotationCache(),
- warningsToSuppress,
- allIncludedFields,
- allExcludedFields
- );
+ Validations
+ .validateProcessedAnnotations(
+ type,
+ config.getAnnotationCache(),
+ warningsToSuppress,
+ allIncludedFields,
+ allExcludedFields);
verifyWithoutExamples(context);
verifyWithExamples(context);
}
private Configuration buildConfig() {
- return Configuration.build(
- type,
- allExcludedFields,
- allIncludedFields,
- nonnullFields,
- fieldCache.getFieldNames(),
- cachedHashCodeInitializer,
- hasRedefinedSuperclass,
- redefinedSubclass,
- usingGetClass,
- warningsToSuppress,
- fieldnameToGetter,
- ignoredAnnotationClassNames,
- actualFields,
- equalExamples,
- unequalExamples
- );
+ return Configuration
+ .build(
+ type,
+ allExcludedFields,
+ allIncludedFields,
+ nonnullFields,
+ fieldCache.getFieldNames(),
+ cachedHashCodeInitializer,
+ hasRedefinedSuperclass,
+ redefinedSubclass,
+ usingGetClass,
+ warningsToSuppress,
+ fieldnameToGetter,
+ ignoredAnnotationClassNames,
+ actualFields,
+ equalExamples,
+ unequalExamples);
}
private void verifyWithoutExamples(Context context) {
Configuration config = context.getConfiguration();
- Checker[] checkers = {
- new SignatureChecker<>(context),
- new AbstractDelegationChecker<>(context),
- new NullChecker<>(context),
- new RecordChecker<>(context),
- new CachedHashCodeChecker<>(config)
- };
+ Checker[] checkers = { new SignatureChecker<>(context), new AbstractDelegationChecker<>(context),
+ new NullChecker<>(context), new RecordChecker<>(context), new CachedHashCodeChecker<>(config) };
for (Checker checker : checkers) {
checker.check();
@@ -481,12 +441,8 @@ private void verifyWithoutExamples(Context context) {
}
private void verifyWithExamples(Context context) {
- Checker[] checkers = {
- new ExamplesChecker<>(context),
- new HierarchyChecker<>(context),
- new FieldsChecker<>(context),
- new MapEntryHashCodeRequirementChecker<>(context)
- };
+ Checker[] checkers = { new ExamplesChecker<>(context), new HierarchyChecker<>(context),
+ new FieldsChecker<>(context), new MapEntryHashCodeRequirementChecker<>(context) };
for (Checker checker : checkers) {
checker.check();
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java
index 2750319d7..55f7c88de 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java
@@ -6,7 +6,8 @@
// CHECKSTYLE OFF: AbbreviationAsWordInName
/**
- * Copied over from spotbugs-annotations to avoid the dependency; see https://github.com/jqno/equalsverifier/issues/1026.
+ * Copied over from spotbugs-annotations to avoid the dependency; see
+ * https://github.com/jqno/equalsverifier/issues/1026.
*/
@Retention(RetentionPolicy.CLASS)
public @interface SuppressFBWarnings {
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java
index 63b3cb93c..71b403652 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java
@@ -3,6 +3,7 @@
import static nl.jqno.equalsverifier.internal.util.Assert.fail;
import java.lang.reflect.Field;
+
import nl.jqno.equalsverifier.internal.SuppressFBWarnings;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.instantiation.ValueProvider;
@@ -45,14 +46,15 @@ private void checkAbstractEqualsAndHashCode() {
if (equalsIsAbstract && hashCodeIsAbstract) {
fail(
- Formatter.of(
- "Abstract delegation: %%'s equals and hashCode methods are both abstract. They should be concrete.",
- type.getSimpleName()
- )
- );
- } else if (equalsIsAbstract) {
+ Formatter
+ .of(
+ "Abstract delegation: %%'s equals and hashCode methods are both abstract. They should be concrete.",
+ type.getSimpleName()));
+ }
+ else if (equalsIsAbstract) {
fail(buildSingleAbstractMethodErrorMessage(type, true, true));
- } else if (hashCodeIsAbstract) {
+ }
+ else if (hashCodeIsAbstract) {
fail(buildSingleAbstractMethodErrorMessage(type, false, true));
}
}
@@ -72,7 +74,8 @@ private void checkAbstractDelegationInFields() {
private Tuple safelyGetTuple(TypeTag tag) {
try {
return valueProvider.provideOrThrow(tag);
- } catch (Exception ignored) {
+ }
+ catch (Exception ignored) {
// If it fails for some reason, any reason, just return null so we can skip the test.
return null;
}
@@ -83,76 +86,61 @@ private void checkAbstractDelegation(T instance, T copy) {
}
private Formatter buildSingleAbstractMethodErrorMessage(
- Class> c,
- boolean isEqualsAbstract,
- boolean bothShouldBeConcrete
- ) {
- return Formatter.of(
- "Abstract delegation: %%'s %% method is abstract, but %% is not.\n%%",
- c.getSimpleName(),
- isEqualsAbstract ? "equals" : "hashCode",
- isEqualsAbstract ? "hashCode" : "equals",
- bothShouldBeConcrete
- ? "Both should be concrete."
- : "Both should be either abstract or concrete."
- );
+ Class> c,
+ boolean isEqualsAbstract,
+ boolean bothShouldBeConcrete) {
+ return Formatter
+ .of(
+ "Abstract delegation: %%'s %% method is abstract, but %% is not.\n%%",
+ c.getSimpleName(),
+ isEqualsAbstract ? "equals" : "hashCode",
+ isEqualsAbstract ? "hashCode" : "equals",
+ bothShouldBeConcrete ? "Both should be concrete." : "Both should be either abstract or concrete.");
}
@SuppressFBWarnings(
- value = "DE_MIGHT_IGNORE",
- justification = "These exceptions will re-occur and be handled later."
- )
- private void checkAbstractMethods(
- Class> instanceClass,
- S instance,
- S copy,
- boolean prefabPossible
- ) {
+ value = "DE_MIGHT_IGNORE",
+ justification = "These exceptions will re-occur and be handled later.")
+ private void checkAbstractMethods(Class> instanceClass, S instance, S copy, boolean prefabPossible) {
try {
instance.equals(copy);
- } catch (AbstractMethodError e) {
- Formatter f = buildAbstractDelegationErrorMessage(
- instanceClass,
- prefabPossible,
- "equals",
- e.getMessage()
- );
+ }
+ catch (AbstractMethodError e) {
+ Formatter f = buildAbstractDelegationErrorMessage(instanceClass, prefabPossible, "equals", e.getMessage());
fail(f, e);
- } catch (Exception ignored) {
+ }
+ catch (Exception ignored) {
// Skip. We only care about AbstractMethodError at this point;
// other errors will be handled later.
}
try {
cachedHashCodeInitializer.getInitializedHashCode(instance);
- } catch (AbstractMethodError e) {
- Formatter f = buildAbstractDelegationErrorMessage(
- instanceClass,
- prefabPossible,
- "hashCode",
- e.getMessage()
- );
+ }
+ catch (AbstractMethodError e) {
+ Formatter f =
+ buildAbstractDelegationErrorMessage(instanceClass, prefabPossible, "hashCode", e.getMessage());
fail(f, e);
- } catch (Exception ignored) {
+ }
+ catch (Exception ignored) {
// Skip. We only care about AbstractMethodError at this point;
// other errors will be handled later.
}
}
private Formatter buildAbstractDelegationErrorMessage(
- Class> c,
- boolean prefabPossible,
- String method,
- String originalMessage
- ) {
+ Class> c,
+ boolean prefabPossible,
+ String method,
+ String originalMessage) {
Formatter prefabFormatter = Formatter.of("\nAdd prefab values for %%.", c.getName());
- return Formatter.of(
- "Abstract delegation: %%'s %% method delegates to an abstract method:\n %%%%",
- c.getSimpleName(),
- method,
- originalMessage,
- prefabPossible ? prefabFormatter.format() : ""
- );
+ return Formatter
+ .of(
+ "Abstract delegation: %%'s %% method delegates to an abstract method:\n %%%%",
+ c.getSimpleName(),
+ method,
+ originalMessage,
+ prefabPossible ? prefabFormatter.format() : "");
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/CachedHashCodeChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/CachedHashCodeChecker.java
index 318e65274..069e480b8 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/CachedHashCodeChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/CachedHashCodeChecker.java
@@ -3,6 +3,7 @@
import static nl.jqno.equalsverifier.internal.util.Assert.*;
import java.util.EnumSet;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer;
import nl.jqno.equalsverifier.internal.util.Configuration;
@@ -25,23 +26,20 @@ public void check() {
}
if (warningsToSuppress.contains(Warning.NONFINAL_FIELDS)) {
fail(
- Formatter.of(
- "Cached hashCode: EqualsVerifier can only check cached hashCodes for immutable classes."
- )
- );
+ Formatter.of("Cached hashCode: EqualsVerifier can only check cached hashCodes for immutable classes."));
}
T reference = cachedHashCodeInitializer.getExample();
if (warningsToSuppress.contains(Warning.NO_EXAMPLE_FOR_CACHED_HASHCODE)) {
if (reference != null) {
fail(
- Formatter.of(
- "Cached hashCode: example must be null if %% is suppressed",
- Warning.NO_EXAMPLE_FOR_CACHED_HASHCODE.name()
- )
- );
+ Formatter
+ .of(
+ "Cached hashCode: example must be null if %% is suppressed",
+ Warning.NO_EXAMPLE_FOR_CACHED_HASHCODE.name()));
}
- } else {
+ }
+ else {
if (reference == null) {
fail(Formatter.of("Cached hashCode: example cannot be null."));
}
@@ -51,14 +49,10 @@ public void check() {
assertEquals(
Formatter.of("Cached hashCode: hashCode is not properly initialized."),
actualHashCode,
- recomputedHashCode
- );
+ recomputedHashCode);
assertFalse(
- Formatter.of(
- "Cached hashCode: example.hashCode() cannot be zero. Please choose a different example."
- ),
- actualHashCode == 0
- );
+ Formatter.of("Cached hashCode: example.hashCode() cannot be zero. Please choose a different example."),
+ actualHashCode == 0);
}
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java
index ba1e91f9f..49821959b 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+
import nl.jqno.equalsverifier.internal.SuppressFBWarnings;
import nl.jqno.equalsverifier.internal.exceptions.AssertionException;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
@@ -65,33 +66,19 @@ private List ensureEnoughExamples(List examples) {
private void checkPreconditions() {
for (T example : equalExamples) {
assertTrue(
- Formatter.of(
- "Precondition:\n %%\nand\n %%\nare of different classes",
- equalExamples.get(0),
- example
- ),
- type.isAssignableFrom(example.getClass())
- );
+ Formatter.of("Precondition:\n %%\nand\n %%\nare of different classes", equalExamples.get(0), example),
+ type.isAssignableFrom(example.getClass()));
}
}
private void checkEqualButNotIdentical(T reference, T other) {
- assertFalse(
- Formatter.of("Precondition: the same object appears twice:\n %%", reference),
- reference == other
- );
+ assertFalse(Formatter.of("Precondition: the same object appears twice:\n %%", reference), reference == other);
assertFalse(
Formatter.of("Precondition: two identical objects appear:\n %%", reference),
- isIdentical(reference, other)
- );
+ isIdentical(reference, other));
assertTrue(
- Formatter.of(
- "Precondition: not all equal objects are equal:\n %%\nand\n %%",
- reference,
- other
- ),
- reference.equals(other)
- );
+ Formatter.of("Precondition: not all equal objects are equal:\n %%\nand\n %%", reference, other),
+ reference.equals(other));
}
private void checkSingle(T reference) {
@@ -108,26 +95,26 @@ private void checkReflexivity(T reference) {
assertEquals(
Formatter.of("Reflexivity: object does not equal itself:\n %%", reference),
reference,
- reference
- );
- } catch (ClassCastException e) {
- Formatter f = Formatter.of(
- "Generics: ClassCastException was thrown. Consider using" +
- " withGenericPrefabValues for the type that triggered the exception."
- );
+ reference);
+ }
+ catch (ClassCastException e) {
+ Formatter f = Formatter
+ .of(
+ "Generics: ClassCastException was thrown. Consider using"
+ + " withGenericPrefabValues for the type that triggered the exception.");
fail(f, e);
}
}
@SuppressFBWarnings(
- value = { "EC_NULL_ARG", "DCN_NULLPOINTER_EXCEPTION" },
- justification = "Check what happens when null is passed into equals."
- )
+ value = { "EC_NULL_ARG", "DCN_NULLPOINTER_EXCEPTION" },
+ justification = "Check what happens when null is passed into equals.")
private void checkNonNullity(T reference) {
try {
boolean nullity = reference.equals(null);
assertFalse(Formatter.of("Non-nullity: true returned for null value"), nullity);
- } catch (NullPointerException e) {
+ }
+ catch (NullPointerException e) {
fail(Formatter.of("Non-nullity: NullPointerException thrown"), e);
}
}
@@ -135,24 +122,25 @@ private void checkNonNullity(T reference) {
private void checkTypeCheck(T reference) {
SomethingElse somethingElse = new SomethingElse();
try {
- Formatter f = Formatter.of(
- "Type-check: equals returns true for an unrelated type.\n" +
- "Add an instanceof or getClass() check."
- );
+ Formatter f = Formatter
+ .of(
+ "Type-check: equals returns true for an unrelated type.\n"
+ + "Add an instanceof or getClass() check.");
assertFalse(f, reference.equals(somethingElse));
- } catch (AssertionException e) {
+ }
+ catch (AssertionException e) {
throw e;
- } catch (ClassCastException e) {
- Formatter f = Formatter.of(
- "Type-check: equals throws ClassCastException.\n" +
- "Add an instanceof or getClass() check."
- );
+ }
+ catch (ClassCastException e) {
+ Formatter f = Formatter
+ .of("Type-check: equals throws ClassCastException.\nAdd an instanceof or getClass() check.");
fail(f, e);
- } catch (Exception e) {
- Formatter f = Formatter.of(
- "Type-check: equals throws %%.\nAdd an instanceof or getClass() check.",
- e.getClass().getSimpleName()
- );
+ }
+ catch (Exception e) {
+ Formatter f = Formatter
+ .of(
+ "Type-check: equals throws %%.\nAdd an instanceof or getClass() check.",
+ e.getClass().getSimpleName());
fail(f, e);
}
}
@@ -160,27 +148,22 @@ private void checkTypeCheck(T reference) {
private void checkHashCode(T reference, T copy) {
int referenceHashCode = cachedHashCodeInitializer.getInitializedHashCode(reference);
assertEquals(
- Formatter.of(
- "hashCode: hashCode should be consistent:\n %% (%%)",
- reference,
- referenceHashCode
- ),
+ Formatter.of("hashCode: hashCode should be consistent:\n %% (%%)", reference, referenceHashCode),
referenceHashCode,
- cachedHashCodeInitializer.getInitializedHashCode(reference)
- );
+ cachedHashCodeInitializer.getInitializedHashCode(reference));
if (!reference.equals(copy)) {
return;
}
int copyHashCode = cachedHashCodeInitializer.getInitializedHashCode(copy);
- Formatter f = Formatter.of(
- "hashCode: hashCodes should be equal:\n %% (%%)\nand\n %% (%%)",
- reference,
- referenceHashCode,
- copy,
- copyHashCode
- );
+ Formatter f = Formatter
+ .of(
+ "hashCode: hashCodes should be equal:\n %% (%%)\nand\n %% (%%)",
+ reference,
+ referenceHashCode,
+ copy,
+ copyHashCode);
assertEquals(f, referenceHashCode, copyHashCode);
}
@@ -198,9 +181,8 @@ private boolean isIdentical(T reference, T other) {
}
@SuppressFBWarnings(
- value = "HE_HASHCODE_USE_OBJECT_EQUALS",
- justification = "The hashCode must be stable, the class has no state so we don't need to override equals"
- )
+ value = "HE_HASHCODE_USE_OBJECT_EQUALS",
+ justification = "The hashCode must be stable, the class has no state so we don't need to override equals")
private static final class SomethingElse {
@Override
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldInspector.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldInspector.java
index 9905082c6..75f2ac147 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldInspector.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldInspector.java
@@ -1,6 +1,7 @@
package nl.jqno.equalsverifier.internal.checkers;
import java.lang.reflect.Field;
+
import nl.jqno.equalsverifier.internal.checkers.fieldchecks.FieldCheck;
import nl.jqno.equalsverifier.internal.reflection.FieldIterable;
import nl.jqno.equalsverifier.internal.reflection.FieldProbe;
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java
index 2aab34ba8..4199ecfd2 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java
@@ -1,6 +1,7 @@
package nl.jqno.equalsverifier.internal.checkers;
import java.util.function.Predicate;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.checkers.fieldchecks.*;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
@@ -34,31 +35,21 @@ public FieldsChecker(Context context) {
final TypeTag typeTag = config.getTypeTag();
final SubjectCreator subjectCreator = context.getSubjectCreator();
- final String cachedHashCodeFieldName = config
- .getCachedHashCodeInitializer()
- .getCachedHashCodeFieldName();
- final Predicate isCachedHashCodeField = p ->
- p.getName().equals(cachedHashCodeFieldName);
+ final String cachedHashCodeFieldName = config.getCachedHashCodeInitializer().getCachedHashCodeFieldName();
+ final Predicate isCachedHashCodeField = p -> p.getName().equals(cachedHashCodeFieldName);
- this.arrayFieldCheck =
- new ArrayFieldCheck<>(subjectCreator, config.getCachedHashCodeInitializer());
+ this.arrayFieldCheck = new ArrayFieldCheck<>(subjectCreator, config.getCachedHashCodeInitializer());
this.floatAndDoubleFieldCheck = new FloatAndDoubleFieldCheck<>(subjectCreator);
- this.mutableStateFieldCheck =
- new MutableStateFieldCheck<>(subjectCreator, isCachedHashCodeField);
+ this.mutableStateFieldCheck = new MutableStateFieldCheck<>(subjectCreator, isCachedHashCodeField);
this.reflexivityFieldCheck = new ReflexivityFieldCheck<>(context);
this.significantFieldCheck = new SignificantFieldCheck<>(context, isCachedHashCodeField);
this.symmetryFieldCheck = new SymmetryFieldCheck<>(subjectCreator);
- this.transientFieldsCheck =
- new TransientFieldsCheck<>(subjectCreator, typeTag, config.getAnnotationCache());
+ this.transientFieldsCheck = new TransientFieldsCheck<>(subjectCreator, typeTag, config.getAnnotationCache());
this.transitivityFieldCheck = new TransitivityFieldCheck<>(subjectCreator);
- this.stringFieldCheck =
- new StringFieldCheck<>(
- subjectCreator,
+ this.stringFieldCheck = new StringFieldCheck<>(subjectCreator,
context.getValueProvider(),
- config.getCachedHashCodeInitializer()
- );
- this.bigDecimalFieldCheck =
- new BigDecimalFieldCheck<>(subjectCreator, config.getCachedHashCodeInitializer());
+ config.getCachedHashCodeInitializer());
+ this.bigDecimalFieldCheck = new BigDecimalFieldCheck<>(subjectCreator, config.getCachedHashCodeInitializer());
this.jpaLazyGetterFieldCheck = new JpaLazyGetterFieldCheck<>(context);
}
@@ -90,20 +81,16 @@ public void check() {
}
AnnotationCache cache = config.getAnnotationCache();
- if (
- cache.hasClassAnnotation(config.getType(), SupportedAnnotations.ENTITY) &&
- !config.getWarningsToSuppress().contains(Warning.JPA_GETTER)
- ) {
+ if (cache.hasClassAnnotation(config.getType(), SupportedAnnotations.ENTITY)
+ && !config.getWarningsToSuppress().contains(Warning.JPA_GETTER)) {
inspector.check(jpaLazyGetterFieldCheck);
}
}
private boolean ignoreMutability(Class> type) {
AnnotationCache cache = config.getAnnotationCache();
- return (
- config.getWarningsToSuppress().contains(Warning.NONFINAL_FIELDS) ||
- cache.hasClassAnnotation(type, SupportedAnnotations.IMMUTABLE) ||
- cache.hasClassAnnotation(type, SupportedAnnotations.ENTITY)
- );
+ return config.getWarningsToSuppress().contains(Warning.NONFINAL_FIELDS)
+ || cache.hasClassAnnotation(type, SupportedAnnotations.IMMUTABLE)
+ || cache.hasClassAnnotation(type, SupportedAnnotations.ENTITY);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java
index 1367ef57f..f2c161b0f 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java
@@ -5,6 +5,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.SuppressFBWarnings;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
@@ -29,15 +30,10 @@ public class HierarchyChecker implements Checker {
public HierarchyChecker(Context context) {
this.config = context.getConfiguration();
- this.strictnessSuppressed =
- config.getWarningsToSuppress().contains(Warning.STRICT_INHERITANCE);
+ this.strictnessSuppressed = config.getWarningsToSuppress().contains(Warning.STRICT_INHERITANCE);
this.hasRedefinedSubclass = config.getRedefinedSubclass() != null;
if (strictnessSuppressed && hasRedefinedSubclass) {
- fail(
- Formatter.of(
- "withRedefinedSubclass and weakInheritanceCheck are mutually exclusive."
- )
- );
+ fail(Formatter.of("withRedefinedSubclass and weakInheritanceCheck are mutually exclusive."));
}
this.type = context.getType();
@@ -68,38 +64,31 @@ private void checkSuperclass() {
T reference = subjectCreator.plain();
Object equalSuper = getEqualSuper(reference);
- Formatter formatter = Formatter.of(
- "Redefined superclass:\n" +
- " %%\nshould not equal superclass instance\n %%\nbut it does.",
- reference,
- equalSuper
- );
+ Formatter formatter = Formatter
+ .of(
+ "Redefined superclass:\n %%\nshould not equal superclass instance\n %%\nbut it does.",
+ reference,
+ equalSuper);
try {
- assertFalse(
- formatter,
- reference.equals(equalSuper) || equalSuper.equals(reference)
- );
- } catch (AbstractMethodError ignored) {
+ assertFalse(formatter, reference.equals(equalSuper) || equalSuper.equals(reference));
+ }
+ catch (AbstractMethodError ignored) {
// In this case, we'll assume all super properties hold.
// The problems we test for, can never occur anyway if you can't instantiate a super
// instance.
}
- } else {
- safelyCheckSuperProperties(
- subjectCreator.plain(),
- subjectCreator.withAllFieldsShallowlyChanged()
- );
+ }
+ else {
+ safelyCheckSuperProperties(subjectCreator.plain(), subjectCreator.withAllFieldsShallowlyChanged());
safelyCheckSuperProperties(
subjectCreator.withAllFieldsDefaulted(),
- subjectCreator.withAllFieldsShallowlyChanged()
- );
+ subjectCreator.withAllFieldsShallowlyChanged());
}
}
@SuppressFBWarnings(
- value = "DCN_NULLPOINTER_EXCEPTION",
- justification = "The equals method in a superclasses can throw an NPE, but it's a specific non-goal to do something with that here."
- )
+ value = "DCN_NULLPOINTER_EXCEPTION",
+ justification = "The equals method in a superclasses can throw an NPE, but it's a specific non-goal to do something with that here.")
private void safelyCheckSuperProperties(T reference, T shallowScrambled) {
if (strictnessSuppressed) {
return;
@@ -109,7 +98,8 @@ private void safelyCheckSuperProperties(T reference, T shallowScrambled) {
try {
checkSuperProperties(reference, equalSuper, shallowScrambled);
- } catch (AbstractMethodError | NullPointerException ignored) {
+ }
+ catch (AbstractMethodError | NullPointerException ignored) {
// In these cases, we'll assume all super properties hold.
// The problems we test for, can never occur anyway if you can't instantiate a super
// instance.
@@ -117,34 +107,30 @@ private void safelyCheckSuperProperties(T reference, T shallowScrambled) {
}
private void checkSuperProperties(T reference, Object equalSuper, T shallow) {
- Formatter symmetryFormatter = Formatter.of(
- "Symmetry:\n %%\ndoes not equal superclass instance\n %%",
- reference,
- equalSuper
- );
+ Formatter symmetryFormatter =
+ Formatter.of("Symmetry:\n %%\ndoes not equal superclass instance\n %%", reference, equalSuper);
assertTrue(symmetryFormatter, reference.equals(equalSuper) && equalSuper.equals(reference));
- Formatter transitivityFormatter = Formatter.of(
- "Transitivity:\n" +
- " %%\nand\n %%\nboth equal superclass instance\n %%\nwhich implies they equal each other.",
- reference,
- shallow,
- equalSuper
- );
+ Formatter transitivityFormatter = Formatter
+ .of(
+ "Transitivity:\n"
+ + " %%\nand\n %%\nboth equal superclass instance\n %%\nwhich implies they equal each other.",
+ reference,
+ shallow,
+ equalSuper);
assertTrue(
transitivityFormatter,
- reference.equals(shallow) || reference.equals(equalSuper) != equalSuper.equals(shallow)
- );
+ reference.equals(shallow) || reference.equals(equalSuper) != equalSuper.equals(shallow));
int referenceHashCode = cachedHashCodeInitializer.getInitializedHashCode(reference);
int equalSuperHashCode = cachedHashCodeInitializer.getInitializedHashCode(equalSuper);
- Formatter superclassFormatter = Formatter.of(
- "Superclass: hashCode for\n %% (%%)\nshould be equal to hashCode for superclass instance\n %% (%%)",
- reference,
- referenceHashCode,
- equalSuper,
- equalSuperHashCode
- );
+ Formatter superclassFormatter = Formatter
+ .of(
+ "Superclass: hashCode for\n %% (%%)\nshould be equal to hashCode for superclass instance\n %% (%%)",
+ reference,
+ referenceHashCode,
+ equalSuper,
+ equalSuperHashCode);
assertTrue(superclassFormatter, referenceHashCode == equalSuperHashCode);
}
@@ -160,26 +146,27 @@ private void checkSubclass() {
T reference = subjectCreator.plain();
@SuppressWarnings("unchecked")
- Class anonymousSubclass = (Class) Instantiator.giveDynamicSubclass(
- reference.getClass() // don't use type directly, as reference may already be a subclass if type was abstract
- );
+ // don't use type directly, as reference may already be a subclass if type was abstract
+ Class realClass = (Class) reference.getClass();
+ Class anonymousSubclass = Instantiator.giveDynamicSubclass(realClass);
T equalSub = subjectCreator.copyIntoSubclass(reference, anonymousSubclass);
if (config.isUsingGetClass()) {
- Formatter formatter = Formatter.of(
- "Subclass: object is equal to an instance of a trivial subclass with" +
- " equal fields:\n %%\nThis should not happen when using getClass().",
- reference
- );
+ Formatter formatter = Formatter
+ .of(
+ "Subclass: object is equal to an instance of a trivial subclass with"
+ + " equal fields:\n %%\nThis should not happen when using getClass().",
+ reference);
assertFalse(formatter, reference.equals(equalSub));
- } else {
- Formatter formatter = Formatter.of(
- "Subclass: object is not equal to an instance of a trivial subclass" +
- " with equal fields:\n %%\n" +
- "Maybe you forgot to add usingGetClass(). Otherwise, consider" +
- " making the class final or use EqualsVerifier.simple().",
- reference
- );
+ }
+ else {
+ Formatter formatter = Formatter
+ .of(
+ "Subclass: object is not equal to an instance of a trivial subclass"
+ + " with equal fields:\n %%\n"
+ + "Maybe you forgot to add usingGetClass(). Otherwise, consider"
+ + " making the class final or use EqualsVerifier.simple().",
+ reference);
assertTrue(formatter, reference.equals(equalSub));
}
}
@@ -191,29 +178,21 @@ private void checkRedefinedSubclass() {
if (methodIsFinal("equals", Object.class)) {
fail(
- Formatter.of(
- "Subclass: %% has a final equals method.\nNo need to supply a redefined subclass.",
- type.getSimpleName()
- )
- );
+ Formatter
+ .of(
+ "Subclass: %% has a final equals method.\nNo need to supply a redefined subclass.",
+ type.getSimpleName()));
}
T reference = subjectCreator.plain();
T redefinedSub = subjectCreator.copyIntoSubclass(reference, redefinedSubclass);
assertFalse(
- Formatter.of(
- "Subclass:\n %%\nequals subclass instance\n %%",
- reference,
- redefinedSub
- ),
- reference.equals(redefinedSub)
- );
+ Formatter.of("Subclass:\n %%\nequals subclass instance\n %%", reference, redefinedSub),
+ reference.equals(redefinedSub));
}
private void checkFinalEqualsMethod() {
- boolean isEntity = config
- .getAnnotationCache()
- .hasClassAnnotation(type, SupportedAnnotations.ENTITY);
+ boolean isEntity = config.getAnnotationCache().hasClassAnnotation(type, SupportedAnnotations.ENTITY);
if (strictnessSuppressed || isEntity || typeIsFinal || hasRedefinedSubclass) {
return;
}
@@ -223,27 +202,24 @@ private void checkFinalEqualsMethod() {
if (config.isUsingGetClass()) {
assertEquals(
- Formatter.of(
- "Finality: equals and hashCode must both be final or both be non-final."
- ),
+ Formatter.of("Finality: equals and hashCode must both be final or both be non-final."),
equalsIsFinal,
- hashCodeIsFinal
- );
- } else {
- Formatter equalsFormatter = Formatter.of(
- "Subclass: equals is not final.\n" +
- "Make your class or your equals method final, or supply an" +
- " instance of a redefined subclass using withRedefinedSubclass" +
- " if equals cannot be final."
- );
+ hashCodeIsFinal);
+ }
+ else {
+ Formatter equalsFormatter = Formatter
+ .of(
+ "Subclass: equals is not final.\nMake your class or your equals method final, or supply an"
+ + " instance of a redefined subclass using withRedefinedSubclass"
+ + " if equals cannot be final.");
assertTrue(equalsFormatter, equalsIsFinal);
- Formatter hashCodeFormatter = Formatter.of(
- "Subclass: hashCode is not final.\n" +
- "Make your class or your hashCode method final, or supply an" +
- " instance of a redefined subclass using withRedefinedSubclass" +
- " if hashCode cannot be final."
- );
+ Formatter hashCodeFormatter = Formatter
+ .of(
+ "Subclass: hashCode is not final.\n"
+ + "Make your class or your hashCode method final, or supply an"
+ + " instance of a redefined subclass using withRedefinedSubclass"
+ + " if hashCode cannot be final.");
assertTrue(hashCodeFormatter, hashCodeIsFinal);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java
index 7e219f02f..9a52da73b 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java
@@ -4,6 +4,7 @@
import java.util.Map;
import java.util.Objects;
+
import nl.jqno.equalsverifier.internal.instantiation.ValueProvider;
import nl.jqno.equalsverifier.internal.util.Configuration;
import nl.jqno.equalsverifier.internal.util.Context;
@@ -22,23 +23,21 @@ public MapEntryHashCodeRequirementChecker(Context context) {
@Override
public void check() {
if (Map.Entry.class.isAssignableFrom(config.getType())) {
- Map.Entry, ?> e = valueProvider
- .>provideOrThrow(config.getTypeTag())
- .getRed();
+ Map.Entry, ?> e = valueProvider.>provideOrThrow(config.getTypeTag()).getRed();
int expectedHashCode = Objects.hashCode(e.getKey()) ^ Objects.hashCode(e.getValue());
int actualHashCode = config.getCachedHashCodeInitializer().getInitializedHashCode(e);
- Formatter f = Formatter.of(
- "Map.Entry: hashCode for\n %%\nshould be %% but was %%.\n" +
- "The hash code of a map entry e is defined as:\n" +
- " (e.getKey()==null ? 0 : e.getKey().hashCode()) ^ (e.getValue()==null ? 0 : e.getValue().hashCode())\n" +
- "or, using Java 8 API:\n" +
- " java.util.Objects.hashCode(e.getKey()) ^ java.util.Objects.hashCode(e.getValue())",
- e,
- expectedHashCode,
- actualHashCode
- );
+ Formatter f = Formatter
+ .of(
+ "Map.Entry: hashCode for\n %%\nshould be %% but was %%.\n"
+ + "The hash code of a map entry e is defined as:\n"
+ + " (e.getKey()==null ? 0 : e.getKey().hashCode()) ^ (e.getValue()==null ? 0 : e.getValue().hashCode())\n"
+ + "or, using Java 8 API:\n"
+ + " java.util.Objects.hashCode(e.getKey()) ^ java.util.Objects.hashCode(e.getValue())",
+ e,
+ expectedHashCode,
+ actualHashCode);
assertEquals(f, expectedHashCode, actualHashCode);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java
index 1ac829845..b803473b1 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java
@@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
+
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.ClassProbe;
import nl.jqno.equalsverifier.internal.reflection.FieldIterable;
@@ -53,18 +54,18 @@ private void verifyRecordPrecondition(T original) {
if (!originalField.equals(copyField)) {
failedFields.add(f.getName());
}
- } catch (IllegalAccessException | InvocationTargetException e) {
+ }
+ catch (IllegalAccessException | InvocationTargetException e) {
fail(Formatter.of("Record: failed to run accessor method: " + accessorMethod));
}
}
fail(
- Formatter.of(
- "Record invariant: constructor invariant failed for field%%: %%",
- failedFields.size() > 1 ? "s" : "",
- failedFields.stream().collect(Collectors.joining(","))
- )
- );
+ Formatter
+ .of(
+ "Record invariant: constructor invariant failed for field%%: %%",
+ failedFields.size() > 1 ? "s" : "",
+ failedFields.stream().collect(Collectors.joining(","))));
}
private Method getAccessorMethodFor(Class type, Field f) {
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java
index 15ae77d89..d48142105 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.reflection.ClassProbe;
import nl.jqno.equalsverifier.internal.util.Context;
@@ -49,12 +50,7 @@ private List getEqualsMethods() {
}
private void failOverloaded(String message) {
- fail(
- Formatter.of(
- "Overloaded: %%.\nSignature should be: public boolean equals(Object obj)",
- message
- )
- );
+ fail(Formatter.of("Overloaded: %%.\nSignature should be: public boolean equals(Object obj)", message));
}
private void checkEquals(Method equals) {
@@ -75,19 +71,14 @@ private void checkEquals(Method equals) {
}
private void checkEqualsIsDefined() {
- boolean dontAllowDirectlyInherited = !warningsToSuppress.contains(
- Warning.INHERITED_DIRECTLY_FROM_OBJECT
- );
+ boolean dontAllowDirectlyInherited = !warningsToSuppress.contains(Warning.INHERITED_DIRECTLY_FROM_OBJECT);
boolean isDirectlyInherited = classProbe.isEqualsInheritedFromObject();
if (dontAllowDirectlyInherited && isDirectlyInherited) {
fail(
- Formatter.of(
- "Equals is inherited directly from Object.\n" +
- "Suppress Warning." +
- Warning.INHERITED_DIRECTLY_FROM_OBJECT.name() +
- " to skip this check."
- )
- );
+ Formatter
+ .of(
+ "Equals is inherited directly from Object.\nSuppress Warning."
+ + Warning.INHERITED_DIRECTLY_FROM_OBJECT.name() + " to skip this check."));
}
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java
index c269b96d8..539432d20 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java
@@ -3,6 +3,7 @@
import static nl.jqno.equalsverifier.internal.util.Assert.assertEquals;
import java.lang.reflect.Array;
+
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.FieldProbe;
import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer;
@@ -13,10 +14,7 @@ public class ArrayFieldCheck implements FieldCheck {
private final SubjectCreator subjectCreator;
private final CachedHashCodeInitializer cachedHashCodeInitializer;
- public ArrayFieldCheck(
- SubjectCreator subjectCreator,
- CachedHashCodeInitializer cachedHashCodeInitializer
- ) {
+ public ArrayFieldCheck(SubjectCreator subjectCreator, CachedHashCodeInitializer cachedHashCodeInitializer) {
this.subjectCreator = subjectCreator;
this.cachedHashCodeInitializer = cachedHashCodeInitializer;
}
@@ -36,7 +34,8 @@ public void execute(FieldProbe fieldProbe) {
if (arrayType.getComponentType().isArray()) {
assertDeep(fieldProbe.getName(), reference, changed);
- } else {
+ }
+ else {
assertArray(fieldProbe.getName(), reference, changed);
}
}
@@ -56,7 +55,8 @@ private Object arrayCopy(Object array) {
for (int i = 0; i < length; i++) {
if (componentType.isArray()) {
Array.set(result, i, arrayCopy(Array.get(array, i)));
- } else {
+ }
+ else {
Array.set(result, i, Array.get(array, i));
}
}
@@ -64,41 +64,32 @@ private Object arrayCopy(Object array) {
}
private void assertDeep(String fieldName, Object reference, Object changed) {
- Formatter eqEqFormatter = Formatter.of(
- "Multidimensional array: ==, regular equals() or Arrays.equals() used" +
- " instead of Arrays.deepEquals() for field %%.",
- fieldName
- );
+ Formatter eqEqFormatter = Formatter
+ .of(
+ "Multidimensional array: ==, regular equals() or Arrays.equals() used"
+ + " instead of Arrays.deepEquals() for field %%.",
+ fieldName);
assertEquals(eqEqFormatter, reference, changed);
- Formatter regularFormatter = Formatter.of(
- "Multidimensional array: regular hashCode() or Arrays.hashCode() used" +
- " instead of Arrays.deepHashCode() for field %%.",
- fieldName
- );
+ Formatter regularFormatter = Formatter
+ .of(
+ "Multidimensional array: regular hashCode() or Arrays.hashCode() used"
+ + " instead of Arrays.deepHashCode() for field %%.",
+ fieldName);
assertEquals(
regularFormatter,
cachedHashCodeInitializer.getInitializedHashCode(reference),
- cachedHashCodeInitializer.getInitializedHashCode(changed)
- );
+ cachedHashCodeInitializer.getInitializedHashCode(changed));
}
private void assertArray(String fieldName, Object reference, Object changed) {
assertEquals(
- Formatter.of(
- "Array: == or regular equals() used instead of Arrays.equals() for field %%.",
- fieldName
- ),
+ Formatter.of("Array: == or regular equals() used instead of Arrays.equals() for field %%.", fieldName),
reference,
- changed
- );
+ changed);
assertEquals(
- Formatter.of(
- "Array: regular hashCode() used instead of Arrays.hashCode() for field %%.",
- fieldName
- ),
+ Formatter.of("Array: regular hashCode() used instead of Arrays.hashCode() for field %%.", fieldName),
cachedHashCodeInitializer.getInitializedHashCode(reference),
- cachedHashCodeInitializer.getInitializedHashCode(changed)
- );
+ cachedHashCodeInitializer.getInitializedHashCode(changed));
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java
index 9ec15ae89..5fbebeea2 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java
@@ -5,6 +5,7 @@
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.FieldProbe;
@@ -19,9 +20,8 @@ public class BigDecimalFieldCheck implements FieldCheck {
private final CachedHashCodeInitializer cachedHashCodeInitializer;
public BigDecimalFieldCheck(
- SubjectCreator subjectCreator,
- CachedHashCodeInitializer cachedHashCodeInitializer
- ) {
+ SubjectCreator subjectCreator,
+ CachedHashCodeInitializer cachedHashCodeInitializer) {
this.subjectCreator = subjectCreator;
this.cachedHashCodeInitializer = cachedHashCodeInitializer;
}
@@ -32,10 +32,7 @@ public void execute(FieldProbe fieldProbe) {
T left = subjectCreator.plain();
BigDecimal referenceValue = (BigDecimal) fieldProbe.getValue(left);
- BigDecimal changedValue = referenceValue.setScale(
- referenceValue.scale() + 1,
- RoundingMode.UNNECESSARY
- );
+ BigDecimal changedValue = referenceValue.setScale(referenceValue.scale() + 1, RoundingMode.UNNECESSARY);
T right = subjectCreator.withFieldSetTo(fieldProbe.getField(), changedValue);
@@ -44,45 +41,31 @@ public void execute(FieldProbe fieldProbe) {
}
}
- private void checkEquals(
- Field field,
- BigDecimal referenceValue,
- BigDecimal changedValue,
- T left,
- T right
- ) {
- Formatter f = Formatter.of(
- ERROR_DOC_TITLE +
- ": object does not equal a copy of itself" +
- " where BigDecimal field %% has a value that is equal using compareTo: %% compared to %%" +
- "\nIf these values should be considered equal then use compareTo rather than equals for this field." +
- "\nIf these values should not be considered equal, suppress Warning.%% to disable this check.",
- field.getName(),
- referenceValue,
- changedValue,
- Warning.BIGDECIMAL_EQUALITY
- );
+ private void checkEquals(Field field, BigDecimal referenceValue, BigDecimal changedValue, T left, T right) {
+ Formatter f = Formatter
+ .of(
+ ERROR_DOC_TITLE + ": object does not equal a copy of itself"
+ + " where BigDecimal field %% has a value that is equal using compareTo: %% compared to %%"
+ + "\nIf these values should be considered equal then use compareTo rather than equals for this field."
+ + "\nIf these values should not be considered equal, suppress Warning.%% to disable this check.",
+ field.getName(),
+ referenceValue,
+ changedValue,
+ Warning.BIGDECIMAL_EQUALITY);
assertEquals(f, left, right);
}
- private void checkHashCode(
- Field field,
- BigDecimal referenceValue,
- BigDecimal changedValue,
- T left,
- T right
- ) {
- Formatter f = Formatter.of(
- ERROR_DOC_TITLE +
- ": hashCode of object does not equal hashCode of a copy of itself" +
- " where BigDecimal field %% has a value that is equal using compareTo: %% compared to %%" +
- "\nIf these values should be considered equal then make sure to derive the same constituent hashCode from this field." +
- "\nIf these values should not be considered equal, suppress Warning.%% to disable this check.",
- field.getName(),
- referenceValue,
- changedValue,
- Warning.BIGDECIMAL_EQUALITY
- );
+ private void checkHashCode(Field field, BigDecimal referenceValue, BigDecimal changedValue, T left, T right) {
+ Formatter f = Formatter
+ .of(
+ ERROR_DOC_TITLE + ": hashCode of object does not equal hashCode of a copy of itself"
+ + " where BigDecimal field %% has a value that is equal using compareTo: %% compared to %%"
+ + "\nIf these values should be considered equal then make sure to derive the same constituent hashCode from this field."
+ + "\nIf these values should not be considered equal, suppress Warning.%% to disable this check.",
+ field.getName(),
+ referenceValue,
+ changedValue,
+ Warning.BIGDECIMAL_EQUALITY);
int leftHashCode = cachedHashCodeInitializer.getInitializedHashCode(left);
int rightHashCode = cachedHashCodeInitializer.getInitializedHashCode(right);
assertEquals(f, leftHashCode, rightHashCode);
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java
index a970b2e3f..805b52164 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java
@@ -21,25 +21,17 @@ public void execute(FieldProbe fieldProbe) {
T reference = subjectCreator.withFieldSetTo(fieldProbe.getField(), Float.NaN);
T copy = subjectCreator.withFieldSetTo(fieldProbe.getField(), Float.NaN);
assertEquals(
- Formatter.of(
- "Float: equals doesn't use Float.compare for field %%.",
- fieldProbe.getName()
- ),
+ Formatter.of("Float: equals doesn't use Float.compare for field %%.", fieldProbe.getName()),
reference,
- copy
- );
+ copy);
}
if (isDouble(type)) {
T reference = subjectCreator.withFieldSetTo(fieldProbe.getField(), Double.NaN);
T copy = subjectCreator.withFieldSetTo(fieldProbe.getField(), Double.NaN);
assertEquals(
- Formatter.of(
- "Double: equals doesn't use Double.compare for field %%.",
- fieldProbe.getName()
- ),
+ Formatter.of("Double: equals doesn't use Double.compare for field %%.", fieldProbe.getName()),
reference,
- copy
- );
+ copy);
}
}
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 1ed068764..fe29fa0eb 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
@@ -7,6 +7,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.function.Function;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
@@ -45,23 +46,20 @@ public void execute(FieldProbe fieldProbe) {
String fieldName = fieldProbe.getName();
String getterName = fieldnameToGetter.apply(fieldName);
- if (
- !fieldIsUsed(fieldProbe.getField(), true) ||
- !fieldIsLazy(fieldName) ||
- Modifier.isFinal(type.getModifiers())
- ) {
+ if (!fieldIsUsed(fieldProbe.getField(), true)
+ || !fieldIsLazy(fieldName)
+ || Modifier.isFinal(type.getModifiers())) {
return;
}
assertTrue(
- Formatter.of(
- "Class %% doesn't contain getter %%() for field %%.",
- classProbe.getType().getSimpleName(),
- getterName,
- fieldName
- ),
- classProbe.hasMethod(getterName)
- );
+ Formatter
+ .of(
+ "Class %% doesn't contain getter %%() for field %%.",
+ classProbe.getType().getSimpleName(),
+ getterName,
+ fieldName),
+ classProbe.hasMethod(getterName));
TypeTag sub = new TypeTag(throwingGetterCreator(getterName));
Tuple tuple = valueProvider.provideOrThrow(sub);
@@ -71,7 +69,8 @@ public void execute(FieldProbe fieldProbe) {
boolean equalsExceptionCaught = false;
try {
red1.equals(red2);
- } catch (EqualsVerifierInternalBugException e) {
+ }
+ catch (EqualsVerifierInternalBugException e) {
equalsExceptionCaught = true;
}
assertEntity(fieldName, "equals", getterName, equalsExceptionCaught);
@@ -80,7 +79,8 @@ public void execute(FieldProbe fieldProbe) {
boolean hashCodeExceptionCaught = false;
try {
red1.hashCode();
- } catch (EqualsVerifierInternalBugException e) {
+ }
+ catch (EqualsVerifierInternalBugException e) {
hashCodeExceptionCaught = true;
}
assertEntity(fieldName, "hashCode", getterName, hashCodeExceptionCaught || !usedInHashcode);
@@ -92,47 +92,35 @@ private boolean fieldIsUsed(Field field, boolean forEquals) {
if (forEquals) {
return !red.equals(blue);
- } else {
+ }
+ else {
return red.hashCode() != blue.hashCode();
}
}
private boolean fieldIsLazy(String fieldName) {
- return (
- annotationCache.hasFieldAnnotation(
- type,
- fieldName,
- SupportedAnnotations.JPA_LINKED_FIELD
- ) ||
- annotationCache.hasFieldAnnotation(type, fieldName, SupportedAnnotations.JPA_LAZY_FIELD)
- );
+ return annotationCache.hasFieldAnnotation(type, fieldName, SupportedAnnotations.JPA_LINKED_FIELD)
+ || annotationCache.hasFieldAnnotation(type, fieldName, SupportedAnnotations.JPA_LAZY_FIELD);
}
private Class throwingGetterCreator(String getterName) {
- return Instantiator.giveDynamicSubclass(
- type,
- getterName,
- builder ->
- builder
- .method(named(getterName))
- .intercept(throwing(EqualsVerifierInternalBugException.class))
- );
+ return Instantiator
+ .giveDynamicSubclass(
+ type,
+ getterName,
+ builder -> builder
+ .method(named(getterName))
+ .intercept(throwing(EqualsVerifierInternalBugException.class)));
}
- private void assertEntity(
- String fieldName,
- String method,
- String getterName,
- boolean assertion
- ) {
+ private void assertEntity(String fieldName, String method, String getterName, boolean assertion) {
assertTrue(
- Formatter.of(
- "JPA Entity: direct reference to field %% used in %% instead of getter %%().",
- fieldName,
- method,
- getterName
- ),
- assertion
- );
+ Formatter
+ .of(
+ "JPA Entity: direct reference to field %% used in %% instead of getter %%().",
+ fieldName,
+ method,
+ getterName),
+ assertion);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java
index 9d71e65ee..0c0415061 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java
@@ -3,6 +3,7 @@
import static nl.jqno.equalsverifier.internal.util.Assert.fail;
import java.util.function.Predicate;
+
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.FieldProbe;
import nl.jqno.equalsverifier.internal.util.Formatter;
@@ -12,10 +13,7 @@ public class MutableStateFieldCheck implements FieldCheck {
private final SubjectCreator subjectCreator;
private final Predicate isCachedHashCodeField;
- public MutableStateFieldCheck(
- SubjectCreator subjectCreator,
- Predicate isCachedHashCodeField
- ) {
+ public MutableStateFieldCheck(SubjectCreator subjectCreator, Predicate isCachedHashCodeField) {
this.subjectCreator = subjectCreator;
this.isCachedHashCodeField = isCachedHashCodeField;
}
@@ -34,10 +32,8 @@ public void execute(FieldProbe fieldProbe) {
boolean equalAfter = reference.equals(changed);
if (equalBefore && !equalAfter && !fieldProbe.isFinal()) {
- String message =
- "Mutability: equals depends on mutable field %%.\n" +
- "Make the field final, suppress Warning.NONFINAL_FIELDS or use" +
- " EqualsVerifier.simple()";
+ String message = "Mutability: equals depends on mutable field %%.\n"
+ + "Make the field final, suppress Warning.NONFINAL_FIELDS or use EqualsVerifier.simple()";
fail(Formatter.of(message, fieldProbe.getName()));
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java
index 7219616f7..9291b92e3 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java
@@ -3,16 +3,14 @@
import static nl.jqno.equalsverifier.internal.util.Assert.fail;
import java.lang.reflect.Field;
+
import nl.jqno.equalsverifier.internal.SuppressFBWarnings;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.FieldMutator;
import nl.jqno.equalsverifier.internal.reflection.FieldProbe;
import nl.jqno.equalsverifier.internal.util.*;
-@SuppressFBWarnings(
- value = "RV_RETURN_VALUE_IGNORED",
- justification = "We only want to see if it throws an exception."
-)
+@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = "We only want to see if it throws an exception.")
public class NullPointerExceptionFieldCheck implements FieldCheck {
private final Configuration config;
@@ -40,13 +38,11 @@ public void execute(FieldProbe fieldProbe) {
FieldMutator fieldMutator = new FieldMutator(fieldProbe);
Object saved = fieldProbe.getValue(reference);
- fieldMutator.setNewValue(
- reference,
- PrimitiveMappers.DEFAULT_VALUE_MAPPER.get(fieldProbe.getType())
- );
+ fieldMutator.setNewValue(reference, PrimitiveMappers.DEFAULT_VALUE_MAPPER.get(fieldProbe.getType()));
performTests(fieldProbe.getField(), subjectCreator.plain(), subjectCreator.plain());
fieldMutator.setNewValue(reference, saved);
- } else {
+ }
+ else {
T changed = subjectCreator.withFieldDefaulted(fieldProbe.getField());
performTests(fieldProbe.getField(), subjectCreator.plain(), changed);
}
@@ -55,67 +51,57 @@ public void execute(FieldProbe fieldProbe) {
private void performTests(Field field, final Object reference, final Object changed) {
handle("equals", "the parameter's field", field, () -> reference.equals(changed));
handle("equals", "the 'this' object's field", field, () -> changed.equals(reference));
- handle(
- "hashCode",
- "field",
- field,
- () -> config.getCachedHashCodeInitializer().getInitializedHashCode(changed)
- );
+ handle("hashCode", "field", field, () -> config.getCachedHashCodeInitializer().getInitializedHashCode(changed));
}
@SuppressFBWarnings(
- value = "DCN_NULLPOINTER_EXCEPTION",
- justification = "We're catching and wrapping it to provide better output to the user."
- )
+ value = "DCN_NULLPOINTER_EXCEPTION",
+ justification = "We're catching and wrapping it to provide better output to the user.")
private void handle(String testedMethodName, String whichOne, Field field, Runnable r) {
try {
r.run();
- } catch (NullPointerException e) {
+ }
+ catch (NullPointerException e) {
npeThrown(testedMethodName, whichOne, field, e);
- } catch (AbstractMethodError e) {
+ }
+ catch (AbstractMethodError e) {
abstractMethodErrorThrown(testedMethodName, field, e);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e) {
classCastExceptionThrown(field, e);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
exceptionThrown(testedMethodName, field, e);
}
}
private void npeThrown(String method, String whichOne, Field field, NullPointerException e) {
- Formatter f = Formatter.of(
- "Non-nullity: %% throws NullPointerException on %% %%.",
- method,
- whichOne,
- field.getName()
- );
+ Formatter f = Formatter
+ .of("Non-nullity: %% throws NullPointerException on %% %%.", method, whichOne, field.getName());
fail(f, e);
}
private void abstractMethodErrorThrown(String method, Field field, AbstractMethodError e) {
- Formatter f = Formatter.of(
- "Abstract delegation: %% throws AbstractMethodError when field %% is null.\n" +
- "Suppress Warning.NULL_FIELDS to disable this check.",
- method,
- field.getName()
- );
+ Formatter f = Formatter
+ .of(
+ "Abstract delegation: %% throws AbstractMethodError when field %% is null.\n"
+ + "Suppress Warning.NULL_FIELDS to disable this check.",
+ method,
+ field.getName());
fail(f, e);
}
private void classCastExceptionThrown(Field field, ClassCastException e) {
- Formatter f = Formatter.of(
- "Generics: ClassCastException was thrown. Consider using withGenericPrefabValues for %%.",
- field.getType().getSimpleName()
- );
+ Formatter f = Formatter
+ .of(
+ "Generics: ClassCastException was thrown. Consider using withGenericPrefabValues for %%.",
+ field.getType().getSimpleName());
fail(f, e);
}
private void exceptionThrown(String method, Field field, Exception e) {
- Formatter f = Formatter.of(
- "%% throws %% when field %% is null.",
- method,
- e.getClass().getSimpleName(),
- field.getName()
- );
+ Formatter f = Formatter
+ .of("%% throws %% when field %% is null.", method, e.getClass().getSimpleName(), field.getName());
fail(f, e);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java
index 9e28dea88..0c5752e01 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java
@@ -6,6 +6,7 @@
import java.lang.reflect.Field;
import java.util.EnumSet;
import java.util.Set;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.instantiation.ValueProvider;
@@ -80,19 +81,18 @@ private void checkValueReflexivity(FieldProbe probe) {
Field field = probe.getField();
String fieldName = field.getName();
TypeTag tag = TypeTag.of(field, typeTag);
- Tuple> tuple = prefabbedFields.contains(fieldName)
- ? fieldCache.get(fieldName)
- : valueProvider.provideOrThrow(tag);
+ Tuple> tuple =
+ prefabbedFields.contains(fieldName) ? fieldCache.get(fieldName) : valueProvider.provideOrThrow(tag);
Object left = subjectCreator.withFieldSetTo(field, tuple.getRed());
Object right = subjectCreator.withFieldSetTo(field, tuple.getRedCopy());
- Formatter f = Formatter.of(
- "Reflexivity: == used instead of .equals() on field: %%" +
- "\nIf this is intentional, consider suppressing Warning.%%",
- probe.getName(),
- Warning.REFERENCE_EQUALITY.toString()
- );
+ Formatter f = Formatter
+ .of(
+ "Reflexivity: == used instead of .equals() on field: %%"
+ + "\nIf this is intentional, consider suppressing Warning.%%",
+ probe.getName(),
+ Warning.REFERENCE_EQUALITY.toString());
assertEquals(f, left, right);
}
@@ -116,31 +116,30 @@ private void checkNullReflexivity(FieldProbe fieldProbe) {
private void checkReflexivityFor(T left, T right) {
if (warningsToSuppress.contains(Warning.IDENTICAL_COPY)) {
- Formatter f = Formatter.of(
- "Unnecessary suppression: %%. Two identical copies are equal.",
- Warning.IDENTICAL_COPY.toString()
- );
+ Formatter f = Formatter
+ .of(
+ "Unnecessary suppression: %%. Two identical copies are equal.",
+ Warning.IDENTICAL_COPY.toString());
assertFalse(f, left.equals(right));
- } else {
- boolean isEntity = annotationCache.hasClassAnnotation(
- typeTag.getType(),
- SupportedAnnotations.ENTITY
- );
+ }
+ else {
+ boolean isEntity = annotationCache.hasClassAnnotation(typeTag.getType(), SupportedAnnotations.ENTITY);
if (isEntity) {
- Formatter f = Formatter.of(
- "Reflexivity: entity does not equal an identical copy of itself:\n %%" +
- "\nIf this is intentional, consider suppressing Warning.%%.",
- left,
- Warning.IDENTICAL_COPY_FOR_VERSIONED_ENTITY.toString()
- );
+ Formatter f = Formatter
+ .of(
+ "Reflexivity: entity does not equal an identical copy of itself:\n %%"
+ + "\nIf this is intentional, consider suppressing Warning.%%.",
+ left,
+ Warning.IDENTICAL_COPY_FOR_VERSIONED_ENTITY.toString());
assertEquals(f, left, right);
- } else {
- Formatter f = Formatter.of(
- "Reflexivity: object does not equal an identical copy of itself:\n %%" +
- "\nIf this is intentional, consider suppressing Warning.%%.",
- left,
- Warning.IDENTICAL_COPY.toString()
- );
+ }
+ else {
+ Formatter f = Formatter
+ .of(
+ "Reflexivity: object does not equal an identical copy of itself:\n %%"
+ + "\nIf this is intentional, consider suppressing Warning.%%.",
+ left,
+ Warning.IDENTICAL_COPY.toString());
assertEquals(f, left, right);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java
index 19d530ea8..77dc6fcc1 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java
@@ -6,6 +6,7 @@
import java.util.EnumSet;
import java.util.Set;
import java.util.function.Predicate;
+
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.FieldProbe;
@@ -46,33 +47,24 @@ public void execute(FieldProbe fieldProbe) {
subjectCreator.plain(),
subjectCreator.withFieldChanged(fieldProbe.getField()),
fieldProbe,
- false
- );
+ false);
if (fieldProbe.canBeDefault(config)) {
checkValues(
subjectCreator.withAllFieldsDefaulted(),
subjectCreator.withAllFieldsDefaulted(),
subjectCreator.withAllFieldsDefaultedExcept(fieldProbe.getField()),
fieldProbe,
- true
- );
+ true);
}
}
- private void checkValues(
- T reference,
- T copy,
- T changed,
- FieldProbe probe,
- boolean testWithNull
- ) {
+ private void checkValues(T reference, T copy, T changed, FieldProbe probe, boolean testWithNull) {
String fieldName = probe.getField().getName();
boolean equalToItself = reference.equals(copy);
boolean equalsChanged = !reference.equals(changed);
- boolean hashCodeChanged =
- cachedHashCodeInitializer.getInitializedHashCode(reference) !=
- cachedHashCodeInitializer.getInitializedHashCode(changed);
+ boolean hashCodeChanged = cachedHashCodeInitializer
+ .getInitializedHashCode(reference) != cachedHashCodeInitializer.getInitializedHashCode(changed);
assertEqualsAndHashCodeRelyOnSameFields(
equalsChanged,
@@ -80,88 +72,69 @@ private void checkValues(
reference,
changed,
fieldName,
- testWithNull
- );
- assertFieldShouldBeIgnored(
- equalToItself,
- equalsChanged,
- reference,
- probe,
- fieldName,
- testWithNull
- );
+ testWithNull);
+ assertFieldShouldBeIgnored(equalToItself, equalsChanged, reference, probe, fieldName, testWithNull);
}
private void assertEqualsAndHashCodeRelyOnSameFields(
- boolean equalsChanged,
- boolean hashCodeChanged,
- T reference,
- T changed,
- String fieldName,
- boolean testWithNull
- ) {
+ boolean equalsChanged,
+ boolean hashCodeChanged,
+ T reference,
+ T changed,
+ String fieldName,
+ boolean testWithNull) {
if (equalsChanged != hashCodeChanged) {
boolean skipEqualsHasMoreThanHashCodeTest =
- warningsToSuppress.contains(Warning.STRICT_HASHCODE) || testWithNull;
+ warningsToSuppress.contains(Warning.STRICT_HASHCODE) || testWithNull;
if (!skipEqualsHasMoreThanHashCodeTest) {
- Formatter formatter = Formatter.of(
- "Significant fields: equals relies on %%, but hashCode does not." +
- "\n %% has hashCode %%\n %% has hashCode %%",
- fieldName,
- reference,
- reference.hashCode(),
- changed,
- changed.hashCode()
- );
+ Formatter formatter = Formatter
+ .of(
+ "Significant fields: equals relies on %%, but hashCode does not."
+ + "\n %% has hashCode %%\n %% has hashCode %%",
+ fieldName,
+ reference,
+ reference.hashCode(),
+ changed,
+ changed.hashCode());
assertFalse(formatter, equalsChanged);
}
- Formatter formatter = Formatter.of(
- "Significant fields: hashCode relies on %%, but equals does not.\n" +
- "These objects are equal, but probably shouldn't be:\n %%\nand\n %%",
- fieldName,
- reference,
- changed
- );
+ Formatter formatter = Formatter
+ .of(
+ "Significant fields: hashCode relies on %%, but equals does not.\n"
+ + "These objects are equal, but probably shouldn't be:\n %%\nand\n %%",
+ fieldName,
+ reference,
+ changed);
assertFalse(formatter, hashCodeChanged);
}
}
private void assertFieldShouldBeIgnored(
- boolean equalToItself,
- boolean equalsChanged,
- T object,
- FieldProbe fieldProbe,
- String fieldName,
- boolean testWithNull
- ) {
+ boolean equalToItself,
+ boolean equalsChanged,
+ T object,
+ FieldProbe fieldProbe,
+ String fieldName,
+ boolean testWithNull) {
if (!shouldAllFieldsBeUsed(fieldProbe) || !isFieldEligible(fieldProbe)) {
return;
}
boolean fieldShouldBeIgnored = ignoredFields.contains(fieldName);
- boolean thisFieldIsMarkedAsId = annotationCache.hasFieldAnnotation(
- type,
- fieldName,
- SupportedAnnotations.ID
- );
+ boolean thisFieldIsMarkedAsId = annotationCache.hasFieldAnnotation(type, fieldName, SupportedAnnotations.ID);
boolean anotherFieldIsMarkedAsId =
- !thisFieldIsMarkedAsId &&
- annotationCache.hasClassAnnotation(type, SupportedAnnotations.ID);
+ !thisFieldIsMarkedAsId && annotationCache.hasClassAnnotation(type, SupportedAnnotations.ID);
if (!fieldIsEmptyAndItsOk(thisFieldIsMarkedAsId, fieldProbe, object)) {
if (!fieldShouldBeIgnored) {
- assertTrue(
- Formatter.of("Significant fields: equals does not use %%.", fieldName),
- equalToItself
- );
+ assertTrue(Formatter.of("Significant fields: equals does not use %%.", fieldName), equalToItself);
}
assertFieldShouldHaveBeenUsed(
fieldName,
equalsChanged,
fieldShouldBeIgnored,
thisFieldIsMarkedAsId,
- anotherFieldIsMarkedAsId
- );
+ anotherFieldIsMarkedAsId);
}
assertFieldShouldNotBeUsed(
fieldName,
@@ -169,66 +142,49 @@ private void assertFieldShouldBeIgnored(
fieldShouldBeIgnored,
thisFieldIsMarkedAsId,
anotherFieldIsMarkedAsId,
- testWithNull
- );
+ testWithNull);
}
private boolean shouldAllFieldsBeUsed(FieldProbe fieldProbe) {
- return (
- !warningsToSuppress.contains(Warning.ALL_FIELDS_SHOULD_BE_USED) &&
- !(warningsToSuppress.contains(Warning.ALL_NONFINAL_FIELDS_SHOULD_BE_USED) &&
- !fieldProbe.isFinal())
- );
+ return !warningsToSuppress.contains(Warning.ALL_FIELDS_SHOULD_BE_USED)
+ && !(warningsToSuppress.contains(Warning.ALL_NONFINAL_FIELDS_SHOULD_BE_USED) && !fieldProbe.isFinal());
}
private boolean isFieldEligible(FieldProbe fieldProbe) {
- return (
- !fieldProbe.isStatic() &&
- !fieldProbe.isTransient() &&
- !fieldProbe.isEmptyOrSingleValueEnum() &&
- !annotationCache.hasFieldAnnotation(
- type,
- fieldProbe.getField().getName(),
- SupportedAnnotations.TRANSIENT
- )
- );
+ return !fieldProbe.isStatic()
+ && !fieldProbe.isTransient()
+ && !fieldProbe.isEmptyOrSingleValueEnum()
+ && !annotationCache
+ .hasFieldAnnotation(type, fieldProbe.getField().getName(), SupportedAnnotations.TRANSIENT);
}
- private boolean fieldIsEmptyAndItsOk(
- boolean thisFieldIsMarkedAsId,
- FieldProbe fieldProbe,
- T object
- ) {
+ private boolean fieldIsEmptyAndItsOk(boolean thisFieldIsMarkedAsId, FieldProbe fieldProbe, T object) {
Object value = fieldProbe.getValue(object);
Class> fieldType = fieldProbe.getType();
Object zero = PrimitiveMappers.DEFAULT_WRAPPED_VALUE_MAPPER.get(fieldType);
boolean fieldIsEmpty = value == null || value.equals(zero);
- return (
- thisFieldIsMarkedAsId &&
- warningsToSuppress.contains(Warning.IDENTICAL_COPY_FOR_VERSIONED_ENTITY) &&
- fieldIsEmpty
- );
+ return thisFieldIsMarkedAsId
+ && warningsToSuppress.contains(Warning.IDENTICAL_COPY_FOR_VERSIONED_ENTITY)
+ && fieldIsEmpty;
}
private void assertFieldShouldHaveBeenUsed(
- String fieldName,
- boolean equalsChanged,
- boolean fieldShouldBeIgnored,
- boolean thisFieldIsMarkedAsId,
- boolean anotherFieldIsMarkedAsId
- ) {
+ String fieldName,
+ boolean equalsChanged,
+ boolean fieldShouldBeIgnored,
+ boolean thisFieldIsMarkedAsId,
+ boolean anotherFieldIsMarkedAsId) {
final String message;
if (thisFieldIsMarkedAsId) {
- message =
- "Significant fields: %% is marked @Id or @EmbeddedId and Warning.SURROGATE_KEY" +
- " is suppressed, but equals does not use it.";
- } else if (anotherFieldIsMarkedAsId) {
- message =
- "Significant fields: equals does not use %%, or it is stateless.\n" +
- "Suppress Warning.SURROGATE_KEY if you want to use only the @Id or" +
- " @EmbeddedId field(s).";
- } else {
+ message = "Significant fields: %% is marked @Id or @EmbeddedId and Warning.SURROGATE_KEY"
+ + " is suppressed, but equals does not use it.";
+ }
+ else if (anotherFieldIsMarkedAsId) {
+ message = "Significant fields: equals does not use %%, or it is stateless.\n"
+ + "Suppress Warning.SURROGATE_KEY if you want to use only the @Id or @EmbeddedId field(s).";
+ }
+ else {
message = "Significant fields: equals does not use %%, or it is stateless.";
}
@@ -236,31 +192,26 @@ private void assertFieldShouldHaveBeenUsed(
}
private void assertFieldShouldNotBeUsed(
- String fieldName,
- boolean equalsChanged,
- boolean fieldShouldBeIgnored,
- boolean thisFieldIsMarkedAsId,
- boolean anotherFieldIsMarkedAsId,
- boolean testWithNull
- ) {
+ String fieldName,
+ boolean equalsChanged,
+ boolean fieldShouldBeIgnored,
+ boolean thisFieldIsMarkedAsId,
+ boolean anotherFieldIsMarkedAsId,
+ boolean testWithNull) {
final String message;
if (thisFieldIsMarkedAsId) {
- message =
- "Significant fields: %% is marked @Id or @EmbeddedId so equals should not use" +
- " it, but it does.\n" +
- "Suppress Warning.SURROGATE_KEY if you want to use only the @Id or" +
- " @EmbeddedId field(s).";
- } else if (anotherFieldIsMarkedAsId) {
- message =
- "Significant fields: equals should not use %% because Warning.SURROGATE_KEY is" +
- " suppressed and it is not marked as @Id or @EmbeddedId, but it does.";
- } else {
+ message = "Significant fields: %% is marked @Id or @EmbeddedId so equals should not use"
+ + " it, but it does.\nSuppress Warning.SURROGATE_KEY if you want to use only the @Id or"
+ + " @EmbeddedId field(s).";
+ }
+ else if (anotherFieldIsMarkedAsId) {
+ message = "Significant fields: equals should not use %% because Warning.SURROGATE_KEY is"
+ + " suppressed and it is not marked as @Id or @EmbeddedId, but it does.";
+ }
+ else {
message = "Significant fields: equals should not use %%, but it does.";
}
- assertTrue(
- Formatter.of(message, fieldName),
- !fieldShouldBeIgnored || !equalsChanged || testWithNull
- );
+ assertTrue(Formatter.of(message, fieldName), !fieldShouldBeIgnored || !equalsChanged || testWithNull);
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java
index 0000feb2f..e8ce7b741 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java
@@ -19,25 +19,18 @@ public class StringFieldCheck implements FieldCheck {
private final ValueProvider valueProvider;
private final CachedHashCodeInitializer cachedHashCodeInitializer;
- @SuppressFBWarnings(
- value = "EI_EXPOSE_REP2",
- justification = "PrefabValues is inherently mutable."
- )
+ @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "PrefabValues is inherently mutable.")
public StringFieldCheck(
- SubjectCreator subjectCreator,
- ValueProvider instanceCreator,
- CachedHashCodeInitializer cachedHashCodeInitializer
- ) {
+ SubjectCreator subjectCreator,
+ ValueProvider instanceCreator,
+ CachedHashCodeInitializer cachedHashCodeInitializer) {
this.subjectCreator = subjectCreator;
this.valueProvider = instanceCreator;
this.cachedHashCodeInitializer = cachedHashCodeInitializer;
}
@Override
- @SuppressFBWarnings(
- value = "DM_CONVERT_CASE",
- justification = "String prefab values are probably not localized."
- )
+ @SuppressFBWarnings(value = "DM_CONVERT_CASE", justification = "String prefab values are probably not localized.")
public void execute(FieldProbe fieldProbe) {
if (String.class.equals(fieldProbe.getType()) && !fieldProbe.isStatic()) {
TypeTag string = new TypeTag(String.class);
@@ -48,25 +41,24 @@ public void execute(FieldProbe fieldProbe) {
try {
reference = subjectCreator.withFieldSetTo(fieldProbe.getField(), red.toLowerCase());
copy = subjectCreator.withFieldSetTo(fieldProbe.getField(), red.toUpperCase());
- } catch (ReflectionException ignored) {
+ }
+ catch (ReflectionException ignored) {
// Differently-cased String is not allowed, so cannot cause problems either.
return;
}
boolean theyAreEqual = reference.equals(copy);
- boolean theirHashCodesAreEqual =
- cachedHashCodeInitializer.getInitializedHashCode(reference) ==
- cachedHashCodeInitializer.getInitializedHashCode(copy);
+ boolean theirHashCodesAreEqual = cachedHashCodeInitializer
+ .getInitializedHashCode(reference) == cachedHashCodeInitializer.getInitializedHashCode(copy);
if (theyAreEqual && !theirHashCodesAreEqual) {
fail(
- Formatter.of(
- ERROR_DOC_TITLE +
- ": class uses equalsIgnoreCase to compare String field %%, but hashCode is case-sensitive." +
- " Use toUpperCase() to determine the hashCode.",
- fieldProbe.getName()
- )
- );
+ Formatter
+ .of(
+ ERROR_DOC_TITLE
+ + ": class uses equalsIgnoreCase to compare String field %%, but hashCode is case-sensitive."
+ + " Use toUpperCase() to determine the hashCode.",
+ fieldProbe.getName()));
}
}
}
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 1bc2d67ad..4ab70b7d5 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
@@ -11,10 +11,7 @@ public class SymmetryFieldCheck implements FieldCheck {
private final SubjectCreator subjectCreator;
- @SuppressFBWarnings(
- value = "EI_EXPOSE_REP2",
- justification = "PrefabValues is inherently mutable."
- )
+ @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "PrefabValues is inherently mutable.")
public SymmetryFieldCheck(SubjectCreator subjectCreator) {
this.subjectCreator = subjectCreator;
}
@@ -32,7 +29,6 @@ public void execute(FieldProbe fieldProbe) {
private void checkSymmetry(T left, T right) {
assertTrue(
Formatter.of("Symmetry: objects are not symmetric:\n %%\nand\n %%", left, right),
- left.equals(right) == right.equals(left)
- );
+ left.equals(right) == right.equals(left));
}
}
diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java
index a0f2c9c3b..fb9ed33e9 100644
--- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java
+++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java
@@ -17,11 +17,7 @@ public class TransientFieldsCheck implements FieldCheck