Enum Warning
- All Implemented Interfaces:
Serializable
,Comparable<Warning>
EqualsVerifier
.- See Also:
-
Enum Constant Summary
Enum ConstantDescriptionSignals that not all fields are relevant in theequals
contract.Signals that non-final fields are not relevant in theequals
contract.Disables the check that equality ofBigDecimal
fields is implemented usingcompareTo
rather thanequals
.Disables the check, when theequals
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 theequals
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 that verifiesequals
is actually overridden.Disables the check that collection fields in JPA, or @Basic fields marked with FetchType.LAZY, should be accessed through their getter methods inequals
andhashCode
methods.Disables the example check for cachedhashCode
.Disables checks for non-final fields on whichequals
andhashCode
depend.Disables the check for reference equality on fields.Disables the check that all fields used inequals
must also be used inhashCode
.Disables some of the stricter inheritance tests.Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in theequals
contract.Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in theequals
contract.Disables the check that transient fields not be part of theequals
contract.Disables checks with fields with value 0 withinequals
,hashCode
andtoString
methods. -
Method Summary
-
Enum Constant Details
-
ALL_FIELDS_SHOULD_BE_USED
Signals that not all fields are relevant in theequals
contract.EqualsVerifier
will not fail if one or more fields do not affect the outcome ofequals
.Only applies to non-transient fields.
-
ALL_NONFINAL_FIELDS_SHOULD_BE_USED
Signals that non-final fields are not relevant in theequals
contract.EqualsVerifier
will not fail if one or more non-final fields do not affect the outcome ofequals
.Only applies to non-transient fields.
-
REFERENCE_EQUALITY
Disables the check for reference equality on fields.EqualsVerifier will check if the
equals
method calls equals on the object fields of the class under test, instead of the==
operator, since normally this signifies a mistake (e.g. comparing string fields with==
).However, sometimes
==
is used intentionally, or the field in question doesn't implementequals
itself, so a call to theequals
method of that field is essentially a reference equality check instead of a value equality check. In these cases, this warning can be suppressed. -
IDENTICAL_COPY
Disables the check, when theequals
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
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.
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,
EqualsVerifier
will fail. -
IDENTICAL_COPY_FOR_VERSIONED_ENTITY
Disables the check, when theequals
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
equals
in the first place.However, when the class is a kind of versioned entity and there is an
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
IDENTICAL_COPY
in these cases, because when theid
s are equal, the objects should be, too, andEqualsVerifier
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,
EqualsVerifier
will NOT fail. -
INHERITED_DIRECTLY_FROM_OBJECT
Disables the check that verifiesequals
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
equals
. -
NO_EXAMPLE_FOR_CACHED_HASHCODE
Disables the example check for cachedhashCode
.The example check verifies that the cached
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.
-
NONFINAL_FIELDS
Disables checks for non-final fields on whichequals
andhashCode
depend.EqualsVerifier
's standard behaviour is to disallow non-final fields being used inequals
andhashCode
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
EqualsVerifier
from checking for non-final fields. -
NULL_FIELDS
Disables checks forNullPointerException
withinequals
,hashCode
andtoString
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
NullPointerException
. -
STRICT_HASHCODE
Disables the check that all fields used inequals
must also be used inhashCode
.This is useful when bringing legacy systems under test, where you don't want to change the existing
hashCode
behaviour but you do want to use EqualsVerifier.Note that
hashCode
s with higher distributions give better performance when used in collections such asHashMap
. Therefore, if possible, you should use all fields that are used inequals
, inhashCode
as well. -
STRICT_INHERITANCE
Disables some of the stricter inheritance tests.EqualsVerifier
's standard behaviour, if T is not final and neither are itsequals
andhashCode
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 redefineequals
orhashCode
don't break the contract; or it asks to call theusingGetClass
method if T usesgetClass()
instead ofinstanceof
in itsequals
method.Some may find that too strict for their liking; suppressing this warning disables that test.
- See Also:
-
SURROGATE_KEY
Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in theequals
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
equals
contract; all other fields may no longer be used inequals
. -
SURROGATE_OR_BUSINESS_KEY
Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in theequals
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.
-
JPA_GETTER
Disables the check that collection fields in JPA, or @Basic fields marked with FetchType.LAZY, should be accessed through their getter methods inequals
andhashCode
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
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. -
TRANSIENT_FIELDS
Disables the check that transient fields not be part of theequals
contract.EqualsVerifier
's standard behaviour is to disallow transient fields being used inequals
andhashCode
methods, since these fields may not be restored to their original state after deserialization, which would breakequals
.If measures are taken that this will never happen, this warning can be suppressed to disable
EqualsVerifier
's transience test. -
BIGDECIMAL_EQUALITY
Disables the check that equality ofBigDecimal
fields is implemented usingcompareTo
rather thanequals
.BigDecimal
objects that are equal usingcompareTo
are not necessarily equal usingequals
, for example the values of 1 and 1.0. For variants of the same value to be considered equal, classes withBigDecimal
fields should usecompareTo
to check equality of non-nullBigDecimal
references and produce the same hashcode for all equal variants.EqualsVerifier
checks for this by default but it can be disabled by suppressing this warning. -
ZERO_FIELDS
Disables checks with fields with value 0 withinequals
,hashCode
andtoString
methods.Sometimes the constructor of a class makes sure no field can be 0. If this is the case, and if the fields cannot be made 0 later in the lifecycle of the class by setters or other methods, suppress this warning to disable the checks with fields that have value 0.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-