Module nl.jqno.equalsverifier
Package nl.jqno.equalsverifier.api
Class MultipleTypeEqualsVerifierApi
java.lang.Object
nl.jqno.equalsverifier.api.MultipleTypeEqualsVerifierApi
- All Implemented Interfaces:
EqualsVerifierApi<Void>
Helps to construct an
EqualsVerifier test for several types at once with a fluent API.- Since:
- 3.2
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMultipleTypeEqualsVerifierApi(List<Class<?>> types, ConfiguredEqualsVerifier ev) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionreport()Performs the verifications of the contracts forequalsandhashCodeand returns a List ofEqualsVerifierReportwith the results of the verifications.Sets modes that influence howEqualsVerifieroperates.Suppresses warnings given byEqualsVerifier.Signals thatgetClassis used in the implementation of theequalsmethod, instead of aninstanceofcheck.voidverify()Performs the verification of the contracts forequalsandhashCodeand throws anAssertionErrorif there is a problem.withFieldnameToGetterConverter(Function<String, String> converter) Determines how a getter name can be derived from a field name.withGenericPrefabValues(Class<S> otherType, Func.Func1<?, S> factory) Adds a factory to generate prefabricated values for instance fields of classes with 1 generic type parameter that EqualsVerifier cannot instantiate by itself.withGenericPrefabValues(Class<S> otherType, Func.Func2<?, ?, 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.withPrefabValues(Class<S> otherType, S red, S blue) Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself.withPrefabValues(Class<S> otherType, S red, S blue, S redCopy) Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself.withResettablePrefabValues(Class<S> otherType, Supplier<S> red, Supplier<S> blue) Adds Suppliers for resettable prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself.
-
Field Details
-
types
-
ev
-
-
Constructor Details
-
MultipleTypeEqualsVerifierApi
Constructor.- Parameters:
types- The classes for which theequalsmethod should be tested.ev- A configuration that can be used for each class.- Since:
- 3.2
-
-
Method Details
-
suppress
Suppresses warnings given byEqualsVerifier. SeeWarningto see what warnings can be suppressed.- Specified by:
suppressin interfaceEqualsVerifierApi<Void>- Parameters:
warnings- A list of warnings to suppress inEqualsVerifier.- Returns:
this, for easy method chaining.
-
set
Sets modes that influence howEqualsVerifieroperates.- Specified by:
setin interfaceEqualsVerifierApi<Void>- Parameters:
modes- A list of modes to influence howEqualsVerifieroperates.- Returns:
this, for easy method chaining.
-
withPrefabValues
Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself. This overload will attempt to copyred. If that fails, use the other overload.- Specified by:
withPrefabValuesin interfaceEqualsVerifierApi<Void>- Type Parameters:
S- The class of the prefabricated values.- Parameters:
otherType- The class of the prefabricated values.red- An instance ofS.blue- Another instance ofS, not equal tored.- Returns:
this, for easy method chaining.
-
withPrefabValues
public <S> MultipleTypeEqualsVerifierApi withPrefabValues(Class<S> otherType, S red, S blue, S redCopy) Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself.- Specified by:
withPrefabValuesin interfaceEqualsVerifierApi<Void>- Type Parameters:
S- The class of the prefabricated values.- Parameters:
otherType- The class of the prefabricated values.red- An instance ofS.blue- Another instance ofS, not equal tored.redCopy- A copy ofred.- Returns:
this, for easy method chaining.
-
withResettablePrefabValues
public <S> MultipleTypeEqualsVerifierApi withResettablePrefabValues(Class<S> otherType, Supplier<S> red, Supplier<S> blue) Adds Suppliers for resettable prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself. Resettable values are values that are created new every time a new instance ofTis constructed within EqualsVerifier. This can be useful whenTmutates its instances ofS.- Specified by:
withResettablePrefabValuesin interfaceEqualsVerifierApi<Void>- Type Parameters:
S- The class of the prefabricated values.- Parameters:
otherType- The class of the prefabricated values.red- An instance ofS.blue- Another instance ofS, not equal tored.- Returns:
this, for easy method chaining.
-
withGenericPrefabValues
public <S> MultipleTypeEqualsVerifierApi withGenericPrefabValues(Class<S> otherType, Func.Func1<?, S> factory) Adds a factory to generate prefabricated values for instance fields of classes with 1 generic type parameter that EqualsVerifier cannot instantiate by itself.- Specified by:
withGenericPrefabValuesin interfaceEqualsVerifierApi<Void>- Type Parameters:
S- The class of the prefabricated values.- Parameters:
otherType- The class of the prefabricated values.factory- A factory to generate an instance ofS, given a value of its generic type parameter.- Returns:
this, for easy method chaining.
-
withGenericPrefabValues
public <S> MultipleTypeEqualsVerifierApi withGenericPrefabValues(Class<S> otherType, Func.Func2<?, ?, 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.- Specified by:
withGenericPrefabValuesin interfaceEqualsVerifierApi<Void>- Type Parameters:
S- The class of the prefabricated values.- Parameters:
otherType- The class of the prefabricated values.factory- A factory to generate an instance ofS, given a value of each of its generic type parameters.- Returns:
this, for easy method chaining.
-
usingGetClass
Signals thatgetClassis used in the implementation of theequalsmethod, instead of aninstanceofcheck.- Specified by:
usingGetClassin interfaceEqualsVerifierApi<Void>- Returns:
this, for easy method chaining.- See Also:
-
withFieldnameToGetterConverter
public MultipleTypeEqualsVerifierApi withFieldnameToGetterConverter(Function<String, String> converter) 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'. This method can be used if your project has a different naming convention.- Specified by:
withFieldnameToGetterConverterin interfaceEqualsVerifierApi<Void>- Parameters:
converter- A function that converts from field name to getter name.- Returns:
this, for easy method chaining.
-
verify
public void verify()Performs the verification of the contracts forequalsandhashCodeand throws anAssertionErrorif there is a problem.- Throws:
AssertionError- If one of the contracts is not met, or ifEqualsVerifier's preconditions do not hold.- Since:
- 0.1
-
report
Performs the verifications of the contracts forequalsandhashCodeand returns a List ofEqualsVerifierReportwith the results of the verifications.- Returns:
- A List of
EqualsVerifierReportthat indicates whether the contracts are met and whetherEqualsVerifier's preconditions hold. - Since:
- 3.0
-