public class RecursiveComparisonConfiguration extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
RecursiveComparisonConfiguration.Builder
Builder to build
RecursiveComparisonConfiguration. |
| Modifier and Type | Field and Description |
|---|---|
static String |
INDENT_LEVEL_2 |
| Constructor and Description |
|---|
RecursiveComparisonConfiguration() |
| Modifier and Type | Method and Description |
|---|---|
static RecursiveComparisonConfiguration.Builder |
builder()
Creates builder to build
RecursiveComparisonConfiguration. |
Stream<Map.Entry<String,Comparator<?>>> |
comparatorByFields() |
void |
compareOnlyFields(String... fieldNamesToCompare)
Adds the given fields and their subfields to the set of fields from the object under test to compare (no other fields will be compared).
|
boolean |
equals(Object obj) |
Comparator<?> |
getComparatorForField(String fieldName) |
Comparator<?> |
getComparatorForType(Class<?> fieldType) |
Set<FieldLocation> |
getComparedFields()
Returns the set of fields to compare from the object under test (no other fields will be compared).
|
FieldComparators |
getFieldComparators() |
Set<String> |
getIgnoredCollectionOrderInFields()
Returns the list fields from the object under test to ignore collection order in the recursive comparison.
|
List<Pattern> |
getIgnoredCollectionOrderInFieldsMatchingRegexes()
Returns the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.
|
Set<String> |
getIgnoredFields()
Returns the set of fields from the object under test to ignore in the recursive comparison.
|
List<Pattern> |
getIgnoredFieldsRegexes() |
List<String> |
getIgnoredOverriddenEqualsForFields() |
List<Pattern> |
getIgnoredOverriddenEqualsForFieldsMatchingRegexes() |
List<Class<?>> |
getIgnoredOverriddenEqualsForTypes() |
Set<Class<?>> |
getIgnoredTypes()
Returns the set of fields from the object under test types to ignore in the recursive comparison.
|
String |
getMessageForField(String fieldName) |
String |
getMessageForType(Class<?> fieldType) |
TypeComparators |
getTypeComparators() |
boolean |
hasComparatorForField(String fieldName) |
boolean |
hasComparatorForType(Class<?> keyType) |
boolean |
hasCustomComparators() |
boolean |
hasCustomMessageForField(String fieldName) |
boolean |
hasCustomMessageForType(Class<?> fieldType) |
int |
hashCode() |
void |
ignoreAllOverriddenEquals()
Force a recursive comparison on all fields (except java types).
|
void |
ignoreCollectionOrder(boolean ignoreCollectionOrder)
Sets whether to ignore collection order in the comparison.
|
void |
ignoreCollectionOrderInFields(String... fieldsToIgnoreCollectionOrder)
Adds the given fields to the list fields from the object under test to ignore collection order in the recursive comparison.
|
void |
ignoreCollectionOrderInFieldsMatchingRegexes(String... regexes)
Adds the given regexes to the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.
|
void |
ignoreFields(String... fieldsToIgnore)
Adds the given fields to the set of fields from the object under test to ignore in the recursive comparison.
|
void |
ignoreFieldsMatchingRegexes(String... regexes)
Allows to ignore in the recursive comparison the object under test fields matching the given regexes.
|
void |
ignoreFieldsOfTypes(Class<?>... types)
Adds the given types to the list fields from the object under test types to ignore in the recursive comparison.
|
void |
ignoreOverriddenEqualsForFields(String... fields)
Adds the given fields to the list of fields to force a recursive comparison on.
|
void |
ignoreOverriddenEqualsForFieldsMatchingRegexes(String... regexes)
Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.
|
void |
ignoreOverriddenEqualsForTypes(Class<?>... types)
Adds the given types to the list of types to force a recursive comparison on.
|
boolean |
isInStrictTypeCheckingMode() |
String |
multiLineDescription(Representation representation) |
void |
registerComparatorForFields(Comparator<?> comparator,
String... fieldLocations)
Registers the given
Comparator to compare the fields at the given locations. |
<T> void |
registerComparatorForType(Comparator<? super T> comparator,
Class<T> type)
Registers the given
Comparator to compare the fields with the given type. |
void |
registerEqualsForFields(BiPredicate<?,?> equals,
String... fieldLocations)
Registers the given
BiPredicate to compare the fields at the given locations. |
<T> void |
registerEqualsForType(BiPredicate<? super T,? super T> equals,
Class<T> type)
Registers the given
BiPredicate to compare the fields with the given type. |
void |
registerErrorMessageForFields(String message,
String... fieldLocations)
Registers the giving message which would be shown when differences in the given fields while comparison occurred.
|
void |
registerErrorMessageForType(String message,
Class<?> clazz)
Registers the giving message which would be shown when differences for the giving type while comparison
occurred.
|
void |
setIgnoreAllActualEmptyOptionalFields(boolean ignoringAllActualEmptyOptionalFields)
Sets whether actual empty optional fields are ignored in the recursive comparison.
|
void |
setIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)
Sets whether actual null fields are ignored in the recursive comparison.
|
void |
setIgnoreAllExpectedNullFields(boolean ignoreAllExpectedNullFields)
Sets whether expected null fields are ignored in the recursive comparison.
|
void |
strictTypeChecking(boolean strictTypeChecking)
Sets whether the recursive comparison will check that actual's type is compatible with expected's type (the same applies for each field).
|
String |
toString() |
void |
useOverriddenEquals()
Force a recursive comparison on all fields (except java types).
|
public static final String INDENT_LEVEL_2
public boolean hasComparatorForField(String fieldName)
public Comparator<?> getComparatorForField(String fieldName)
public boolean hasCustomMessageForField(String fieldName)
public FieldComparators getFieldComparators()
public boolean hasComparatorForType(Class<?> keyType)
public boolean hasCustomComparators()
public Comparator<?> getComparatorForType(Class<?> fieldType)
public boolean hasCustomMessageForType(Class<?> fieldType)
public TypeComparators getTypeComparators()
public void setIgnoreAllActualEmptyOptionalFields(boolean ignoringAllActualEmptyOptionalFields)
See RecursiveComparisonAssert.ignoringActualNullFields() for code examples.
ignoringAllActualEmptyOptionalFields - whether to ignore actual empty optional fields in the recursive comparisonpublic void setIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)
See RecursiveComparisonAssert.ignoringActualNullFields() for code examples.
ignoreAllActualNullFields - whether to ignore actual null fields in the recursive comparisonpublic void setIgnoreAllExpectedNullFields(boolean ignoreAllExpectedNullFields)
See RecursiveComparisonAssert.ignoringExpectedNullFields() for code examples.
ignoreAllExpectedNullFields - whether to ignore expected null fields in the recursive comparisonpublic void ignoreFields(String... fieldsToIgnore)
The fields are ignored by name, not by value.
See RecursiveComparisonAssert#ignoringFields(String...) for examples.
fieldsToIgnore - the fields of the object under test to ignore in the comparison.public void compareOnlyFields(String... fieldNamesToCompare)
The fields are specified by name, not by value, you can specify person.name but not "Jack" as "Jack" is not a field value.
Specifying a field will make all its subfields to be compared, for example specifying person will lead to compare person.name, person.address ...
on the other hand if you specify person.name, person won't be compared but person.name will be.
See RecursiveComparisonAssert#comparingOnlyFields(String...) for examples.
fieldNamesToCompare - the fields of the object under test to compare in the comparison.public void ignoreFieldsMatchingRegexes(String... regexes)
See RecursiveComparisonAssert#ignoringFieldsMatchingRegexes(String...) for examples.
regexes - regexes used to ignore fields in the comparison.public void ignoreFieldsOfTypes(Class<?>... types)
Note that if some object under test fields are null, they are not ignored by this method as their type can't be evaluated.
See RecursiveComparisonAssert#ignoringFieldsOfTypes(Class...) for examples.
types - the types of the object under test to ignore in the comparison.public Set<String> getIgnoredFields()
public Set<FieldLocation> getComparedFields()
public Set<Class<?>> getIgnoredTypes()
public void ignoreAllOverriddenEquals()
See RecursiveComparisonAssert.ignoringAllOverriddenEquals() for examples.
public void useOverriddenEquals()
See RecursiveComparisonAssert.usingOverriddenEquals() for examples.
public void ignoreOverriddenEqualsForFields(String... fields)
See RecursiveComparisonAssert#ignoringOverriddenEqualsForFields(String...) for examples.
fields - the fields to force a recursive comparison on.public void ignoreOverriddenEqualsForFieldsMatchingRegexes(String... regexes)
See RecursiveComparisonAssert#ignoringOverriddenEqualsForFieldsMatchingRegexes(String...) for examples.
regexes - regexes used to specify the fields we want to force a recursive comparison on.public void ignoreOverriddenEqualsForTypes(Class<?>... types)
See RecursiveComparisonAssert#ignoringOverriddenEqualsForTypes(Class...) for examples.
types - the types to the list of types to force a recursive comparison on.public void ignoreCollectionOrder(boolean ignoreCollectionOrder)
See RecursiveComparisonAssert.ignoringCollectionOrder() for code examples.
ignoreCollectionOrder - whether to ignore collection order in the comparison.public void ignoreCollectionOrderInFields(String... fieldsToIgnoreCollectionOrder)
See RecursiveComparisonAssert#ignoringCollectionOrderInFields(String...) for examples.
fieldsToIgnoreCollectionOrder - the fields of the object under test to ignore collection order in the comparison.public Set<String> getIgnoredCollectionOrderInFields()
public void ignoreCollectionOrderInFieldsMatchingRegexes(String... regexes)
See RecursiveComparisonAssert#ignoringCollectionOrderInFieldsMatchingRegexes(String...) for examples.
regexes - regexes used to find the object under test fields to ignore collection order in in the comparison.public List<Pattern> getIgnoredCollectionOrderInFieldsMatchingRegexes()
public <T> void registerComparatorForType(Comparator<? super T> comparator, Class<T> type)
Comparator to compare the fields with the given type.
Comparators registered with this method have less precedence than comparators registered with
registerComparatorForFields(Comparator, String...).
Note that registering a Comparator for a given type will override the previously registered BiPredicate/Comparator (if any).
See RecursiveComparisonAssert.withComparatorForType(Comparator, Class) for examples.
T - the class type to register a comparator forcomparator - the Comparator to use to compare the given typetype - the type to be compared with the given comparator.NullPointerException - if the given comparator is null.public <T> void registerEqualsForType(BiPredicate<? super T,? super T> equals, Class<T> type)
BiPredicate to compare the fields with the given type.
BiPredicates specified with this method have less precedence than the ones registered with
registerEqualsForFields(BiPredicate, String...)
or comparators registered with registerComparatorForFields(Comparator, String...).
Note that registering a BiPredicate for a given type will override the previously registered BiPredicate/Comparator (if any).
See RecursiveComparisonAssert.withEqualsForType(BiPredicate, Class) for examples.
T - the class type to register a comparator forequals - the equals implementation to compare the given typetype - the type to be compared with the given equals implementation .NullPointerException - if the given BiPredicate is null.public void registerComparatorForFields(Comparator<?> comparator, String... fieldLocations)
Comparator to compare the fields at the given locations.
The fields must be specified from the root object, for example if Foo has a Bar field and both have an id field,
one can register a comparator for Foo and Bar's id by calling:
registerComparatorForFields(idComparator, "foo.id", "foo.bar.id")
Comparators registered with this method have precedence over comparators registered with registerComparatorForType(Comparator, Class).
Note that registering a Comparator for a given field will override the previously registered BiPredicate/Comparator (if any).
See RecursiveComparisonAssert#withComparatorForFields(Comparator, String...) for examples.
comparator - the Comparator to use to compare the given fieldfieldLocations - the locations from the root object of the fields the comparator should be used forNullPointerException - if the given comparator is null.public void registerEqualsForFields(BiPredicate<?,?> equals, String... fieldLocations)
BiPredicate to compare the fields at the given locations.
The fields must be specified from the root object, for example if Foo has a Bar field and both have an id field,
one can register a BiPredicate for Foo and Bar's id by calling:
registerEqualsForFields(idBiPredicate, "foo.id", "foo.bar.id")
BiPredicates registered with this method have precedence over the ones registered with registerEqualsForType(BiPredicate, Class)
or the comparators registered with registerComparatorForType(Comparator, Class).
Note that registering a BiPredicate for a given field will override the previously registered BiPredicate/Comparator (if any).
See RecursiveComparisonAssert#withEqualsForFields(BiPredicate, String...) for examples.
equals - the equals implementation to compare the given fields.fieldLocations - the locations from the root object of the fields the comparator should be used forNullPointerException - if the given BiPredicate is null.public void registerErrorMessageForFields(String message, String... fieldLocations)
The fields must be specified from the root object, for example if Foo has a Bar field and both
have an id field, one can register a message for Foo and Bar's id by calling:
registerErrorMessageForFields("some message", "foo.id", "foo.bar.id")
Messages registered with this method have precedence over the ones registered with registerErrorMessageForType(String, Class).
In case of null as message the default error message will be used (See ComparisonDifference.DEFAULT_TEMPLATE).
message - the error message that will be thrown when comparison error occurredfieldLocations - the field locations the error message should be used forpublic void registerErrorMessageForType(String message, Class<?> clazz)
Message registered with this method have less precedence than the ones registered with registerErrorMessageForFields(String, String...).
In case of null as message the default error message will be used (See ComparisonDifference.DEFAULT_TEMPLATE).
message - the error message that will be thrown when comparison error occurredclazz - the type the error message should be used forpublic void strictTypeChecking(boolean strictTypeChecking)
See RecursiveComparisonAssert.withStrictTypeChecking() for code examples.
strictTypeChecking - whether the recursive comparison will check that actual's type is compatible with expected's type.public boolean isInStrictTypeCheckingMode()
public List<Pattern> getIgnoredOverriddenEqualsForFieldsMatchingRegexes()
public Stream<Map.Entry<String,Comparator<?>>> comparatorByFields()
public String multiLineDescription(Representation representation)
public static RecursiveComparisonConfiguration.Builder builder()
RecursiveComparisonConfiguration.Copyright © 2025. All rights reserved.