Class RecursiveComparisonConfiguration
- java.lang.Object
-
- org.assertj.core.api.recursive.AbstractRecursiveOperationConfiguration
-
- org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration
-
public class RecursiveComparisonConfiguration extends AbstractRecursiveOperationConfiguration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRecursiveComparisonConfiguration.BuilderBuilder to buildRecursiveComparisonConfiguration.-
Nested classes/interfaces inherited from class org.assertj.core.api.recursive.AbstractRecursiveOperationConfiguration
AbstractRecursiveOperationConfiguration.AbstractBuilder<BUILDER_TYPE extends AbstractRecursiveOperationConfiguration.AbstractBuilder<BUILDER_TYPE>>
-
-
Field Summary
-
Fields inherited from class org.assertj.core.api.recursive.AbstractRecursiveOperationConfiguration
DEFAULT_DELIMITER
-
-
Constructor Summary
Constructors Modifier Constructor Description RecursiveComparisonConfiguration()privateRecursiveComparisonConfiguration(RecursiveComparisonConfiguration.Builder builder)RecursiveComparisonConfiguration(Representation representation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallowComparingEnumAgainstString(boolean compareEnumAgainstString)Allows the recursive comparison to compare an enum field against a string field.static RecursiveComparisonConfiguration.Builderbuilder()Creates builder to buildRecursiveComparisonConfiguration.private java.util.Optional<java.util.Map.Entry<FieldLocation,java.lang.String>>checkComparedFieldExists(java.lang.Object actual, FieldLocation comparedFieldLocation)(package private) voidcheckComparedFieldsExist(java.lang.Object actual)java.util.stream.Stream<java.util.Map.Entry<java.lang.String,java.util.Comparator<?>>>comparatorByFields()(package private) java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>>>comparatorByTypes()voidcompareOnlyFields(java.lang.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).voidcompareOnlyFieldsOfTypes(java.lang.Class<?>... typesToCompare)Adds the given fields of types and their subfields to the set of fields from the object under test to compare (fields of other types will not be compared).private voiddescribeComparatorForFields(java.lang.StringBuilder description)private voiddescribeComparatorForRegexFields(java.lang.StringBuilder description)private voiddescribeComparatorForTypes(java.lang.StringBuilder description)private java.lang.StringdescribeComparedFields()private voiddescribeComparedFields(java.lang.StringBuilder description)private java.lang.StringdescribeComparedTypes()private voiddescribeComparedTypes(java.lang.StringBuilder description)private voiddescribeCompareEnumAgainstString(java.lang.StringBuilder description)private voiddescribeErrorMessagesForFields(java.lang.StringBuilder description)private voiddescribeErrorMessagesForType(java.lang.StringBuilder description)protected voiddescribeIgnoreAllActualEmptyOptionalFields(java.lang.StringBuilder description)protected voiddescribeIgnoreAllActualNullFields(java.lang.StringBuilder description)private voiddescribeIgnoreAllExpectedNullFields(java.lang.StringBuilder description)private voiddescribeIgnoreCollectionOrder(java.lang.StringBuilder description)private java.lang.StringdescribeIgnoredCollectionOrderInFields()private voiddescribeIgnoredCollectionOrderInFields(java.lang.StringBuilder description)private voiddescribeIgnoredCollectionOrderInFieldsMatchingRegexes(java.lang.StringBuilder description)private java.lang.StringdescribeIgnoredOverriddenEqualsForFields()private java.lang.StringdescribeIgnoredOverriddenEqualsForTypes(Representation representation)private voiddescribeIgnoredOverriddenEqualsMethods(java.lang.StringBuilder description, Representation representation)private voiddescribeIgnoredTypes(java.lang.StringBuilder description)private voiddescribeIgnoredTypesRegexes(java.lang.StringBuilder description)private voiddescribeIntrospectionStrategy(java.lang.StringBuilder description)private voiddescribeOverriddenEqualsMethodsUsage(java.lang.StringBuilder description, Representation representation)private voiddescribeRegisteredComparatorByTypes(java.lang.StringBuilder description)private voiddescribeRegisteredComparatorForFields(java.lang.StringBuilder description)private voiddescribeRegisteredErrorMessagesForFields(java.lang.StringBuilder description)private voiddescribeRegisteredErrorMessagesForTypes(java.lang.StringBuilder description)private voiddescribeTypeCheckingStrictness(java.lang.StringBuilder description)private DualValuedualValueForField(DualValue parentDualValue, java.lang.String fieldName)booleanequals(java.lang.Object obj)(package private) booleanexactlyMatchesAnyComparedFields(DualValue dualValue)private java.lang.StringformatRegisteredComparatorByType(java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>> next)private java.lang.StringformatRegisteredComparatorForField(java.util.Map.Entry<java.lang.String,java.util.Comparator<?>> comparatorForField)private java.lang.StringformatRegisteredComparatorForRegexFields(java.util.Map.Entry<java.util.List<java.util.regex.Pattern>,java.util.Comparator<?>> comparatorForRegexFields)private static java.lang.StringformatUnknownComparedField(FieldLocation fieldLocation, java.lang.String unknownNodeNameElement)java.util.Set<java.lang.String>getActualChildrenNodeNamesToCompare(DualValue dualValue)(package private) java.util.Set<java.lang.String>getChildrenNodeNamesOf(java.lang.Object instance)java.util.Comparator<?>getComparatorForField(java.lang.String fieldName)java.util.Comparator<?>getComparatorForType(java.lang.Class<?> fieldType)java.util.Set<FieldLocation>getComparedFields()Returns the set of fields to compare from the object under test (no other fields will be compared).java.util.Set<java.lang.Class<?>>getComparedTypes()Returns the set of type to compare from the object under test (fields of other types will not be compared).FieldComparatorsgetFieldComparators()booleangetIgnoreAllActualEmptyOptionalFields()booleangetIgnoreAllActualNullFields()booleangetIgnoreAllExpectedNullFields()booleangetIgnoreAllOverriddenEquals()booleangetIgnoreCollectionOrder()java.util.Set<java.lang.String>getIgnoredCollectionOrderInFields()Returns the list fields from the object under test to ignore collection order in the recursive comparison.java.util.List<java.util.regex.Pattern>getIgnoredCollectionOrderInFieldsMatchingRegexes()Returns the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.java.util.List<java.lang.String>getIgnoredOverriddenEqualsForFields()java.util.List<java.util.regex.Pattern>getIgnoredOverriddenEqualsForFieldsMatchingRegexes()java.util.List<java.lang.Class<?>>getIgnoredOverriddenEqualsForTypes()RecursiveComparisonIntrospectionStrategygetIntrospectionStrategy()java.lang.StringgetMessageForField(java.lang.String fieldName)java.lang.StringgetMessageForType(java.lang.Class<?> fieldType)RepresentationgetRepresentation()TypeComparatorsgetTypeComparators()(package private) java.lang.ObjectgetValue(java.lang.String name, java.lang.Object instance)booleanhasComparatorForField(java.lang.String fieldName)booleanhasComparatorForType(java.lang.Class<?> keyType)(package private) booleanhasComparedTypes()(package private) booleanhasCustomComparator(DualValue dualValue)booleanhasCustomComparators()booleanhasCustomMessageForField(java.lang.String fieldName)booleanhasCustomMessageForType(java.lang.Class<?> fieldType)inthashCode()(package private) booleanhierarchyMatchesAnyComparedTypes(DualValue dualValue)voidignoreAllOverriddenEquals()Force a recursive comparison on all fields (except java types).voidignoreCollectionOrder(boolean ignoreCollectionOrder)Sets whether to ignore collection order in the comparison.voidignoreCollectionOrderInFields(java.lang.String... fieldsToIgnoreCollectionOrder)Adds the given fields to the list fields from the object under test to ignore collection order in the recursive comparison.voidignoreCollectionOrderInFieldsMatchingRegexes(java.lang.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.voidignoreOverriddenEqualsForFields(java.lang.String... fields)Adds the given fields to the list of fields to force a recursive comparison on.voidignoreOverriddenEqualsForFieldsMatchingRegexes(java.lang.String... regexes)Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.voidignoreOverriddenEqualsForTypes(java.lang.Class<?>... types)Adds the given types to the list of types to force a recursive comparison on.booleanisComparingEnumAgainstStringAllowed()private booleanisConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods()private booleanisFieldOfTypeToCompare(DualValue dualValue)booleanisInStrictTypeCheckingMode()booleanisOrIsChildOfAnyComparedFields(FieldLocation currentFieldLocation)private booleanmatchesAnIgnoredCollectionOrderInField(FieldLocation fieldLocation)private booleanmatchesAnIgnoredCollectionOrderInFieldRegex(FieldLocation fieldLocation)private booleanmatchesAnIgnoredEmptyOptionalField(DualValue dualValue)private booleanmatchesAnIgnoredFieldType(DualValue dualValue)private booleanmatchesAnIgnoredNullField(DualValue dualValue)private booleanmatchesAnIgnoredOverriddenEqualsField(DualValue dualValue)private booleanmatchesAnIgnoredOverriddenEqualsRegex(FieldLocation fieldLocation)private booleanmatchesAnIgnoredOverriddenEqualsType(java.lang.Class<?> clazz)private booleanmatchesAnIgnoredType(java.lang.Object actual)private static java.util.function.Predicate<FieldLocation>matchesComparedField(FieldLocation field)(package private) booleanmatchesOrIsChildOfFieldMatchingAnyComparedTypes(DualValue dualValue)java.lang.StringmultiLineDescription(Representation representation)voidregisterComparatorForFields(java.util.Comparator<?> comparator, java.lang.String... fieldLocations)Registers the givenComparatorto compare the fields at the given locations.<T> voidregisterComparatorForType(java.util.Comparator<? super T> comparator, java.lang.Class<T> type)Registers the givenComparatorto compare the fields with the given type.voidregisterEqualsForFields(java.util.function.BiPredicate<?,?> equals, java.lang.String... fieldLocations)Registers the givenBiPredicateto compare the fields at the given locations.voidregisterEqualsForFieldsMatchingRegexes(java.util.function.BiPredicate<?,?> equals, java.lang.String... regexes)Allows to register aBiPredicateto compare fields whose location matches the given regexes.<T> voidregisterEqualsForType(java.util.function.BiPredicate<? super T,? super T> equals, java.lang.Class<T> type)Registers the givenBiPredicateto compare the fields with the given type.voidregisterErrorMessageForFields(java.lang.String message, java.lang.String... fieldLocations)Registers the giving message which would be shown when differences in the given fields while comparison occurred.voidregisterErrorMessageForType(java.lang.String message, java.lang.Class<?> clazz)Registers the giving message which would be shown when differences for the giving type while comparison occurred.private voidregisterFieldLocationOfFieldsOfTypesToCompare(DualValue dualValue)voidregisterFieldLocationToCompareBecauseOfTypesToCompare(FieldLocation fieldLocation)voidsetIgnoreAllActualEmptyOptionalFields(boolean ignoringAllActualEmptyOptionalFields)Sets whether actual empty optional fields are ignored in the recursive comparison.voidsetIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)Sets whether actual null fields are ignored in the recursive comparison.voidsetIgnoreAllExpectedNullFields(boolean ignoreAllExpectedNullFields)Sets whether expected null fields are ignored in the recursive comparison.voidsetIntrospectionStrategy(RecursiveComparisonIntrospectionStrategy introspectionStrategy)Defines how objects are introspected in the recursive comparison.private booleanshouldBeCompared(DualValue dualValue)booleanshouldIgnore(DualValue dualValue)booleanshouldIgnoreCollectionOrder(FieldLocation fieldLocation)private booleanshouldIgnoreFieldBasedOnFieldLocation(FieldLocation fieldLocation)private booleanshouldIgnoreFieldBasedOnFieldValue(DualValue dualValue)booleanshouldIgnoreOverriddenEqualsOf(java.lang.Class<?> clazz)booleanshouldIgnoreOverriddenEqualsOf(DualValue dualValue)booleanshouldNotEvaluate(DualValue dualValue)(package private) booleansomeComparedFieldsHaveBeenSpecified()voidstrictTypeChecking(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).private static java.util.ComparatortoComparator(java.util.function.BiPredicate equals)java.lang.StringtoString()voiduseOverriddenEquals()Force a recursive comparison on all fields (except java types).-
Methods inherited from class org.assertj.core.api.recursive.AbstractRecursiveOperationConfiguration
asWrapperIfPrimitiveType, describeIgnoredFields, describeIgnoredFieldsRegexes, describeIgnoredTypes, describeRegexes, getIgnoredFields, getIgnoredFieldsRegexes, getIgnoredTypes, getIgnoredTypesRegexes, ignoreFields, ignoreFieldsMatchingRegexes, ignoreFieldsOfTypes, ignoreFieldsOfTypesMatchingRegexes, join, matchesAnIgnoredField, matchesAnIgnoredFieldRegex
-
-
-
-
Field Detail
-
DEFAULT_IGNORE_ALL_OVERRIDDEN_EQUALS
private static final boolean DEFAULT_IGNORE_ALL_OVERRIDDEN_EQUALS
- See Also:
- Constant Field Values
-
INDENT_LEVEL_2
public static final java.lang.String INDENT_LEVEL_2
- See Also:
- Constant Field Values
-
representation
private final Representation representation
-
DEFAULT_RECURSIVE_COMPARISON_INTROSPECTION_STRATEGY
public static final DefaultRecursiveComparisonIntrospectionStrategy DEFAULT_RECURSIVE_COMPARISON_INTROSPECTION_STRATEGY
-
strictTypeChecking
private boolean strictTypeChecking
-
ignoreAllActualNullFields
private boolean ignoreAllActualNullFields
-
ignoreAllActualEmptyOptionalFields
private boolean ignoreAllActualEmptyOptionalFields
-
ignoreAllExpectedNullFields
private boolean ignoreAllExpectedNullFields
-
comparedFields
private java.util.Set<FieldLocation> comparedFields
-
comparedTypes
private java.util.Set<java.lang.Class<?>> comparedTypes
-
ignoredOverriddenEqualsForTypes
private final java.util.List<java.lang.Class<?>> ignoredOverriddenEqualsForTypes
-
ignoredOverriddenEqualsForFields
private java.util.List<java.lang.String> ignoredOverriddenEqualsForFields
-
ignoredOverriddenEqualsForFieldsMatchingRegexes
private final java.util.List<java.util.regex.Pattern> ignoredOverriddenEqualsForFieldsMatchingRegexes
-
ignoreAllOverriddenEquals
private boolean ignoreAllOverriddenEquals
-
ignoreCollectionOrder
private boolean ignoreCollectionOrder
-
ignoredCollectionOrderInFields
private java.util.Set<java.lang.String> ignoredCollectionOrderInFields
-
ignoredCollectionOrderInFieldsMatchingRegexes
private final java.util.List<java.util.regex.Pattern> ignoredCollectionOrderInFieldsMatchingRegexes
-
typeComparators
private TypeComparators typeComparators
-
fieldComparators
private FieldComparators fieldComparators
-
typeMessages
private TypeMessages typeMessages
-
fieldMessages
private FieldMessages fieldMessages
-
fieldLocationsToCompareBecauseOfTypesToCompare
private final java.util.Set<FieldLocation> fieldLocationsToCompareBecauseOfTypesToCompare
-
introspectionStrategy
private RecursiveComparisonIntrospectionStrategy introspectionStrategy
-
compareEnumAgainstString
private boolean compareEnumAgainstString
-
-
Constructor Detail
-
RecursiveComparisonConfiguration
private RecursiveComparisonConfiguration(RecursiveComparisonConfiguration.Builder builder)
-
RecursiveComparisonConfiguration
public RecursiveComparisonConfiguration(Representation representation)
-
RecursiveComparisonConfiguration
public RecursiveComparisonConfiguration()
-
-
Method Detail
-
registerFieldLocationToCompareBecauseOfTypesToCompare
public void registerFieldLocationToCompareBecauseOfTypesToCompare(FieldLocation fieldLocation)
-
getRepresentation
public Representation getRepresentation()
-
hasComparatorForField
public boolean hasComparatorForField(java.lang.String fieldName)
-
getComparatorForField
public java.util.Comparator<?> getComparatorForField(java.lang.String fieldName)
-
hasCustomMessageForField
public boolean hasCustomMessageForField(java.lang.String fieldName)
-
getMessageForField
public java.lang.String getMessageForField(java.lang.String fieldName)
-
getFieldComparators
public FieldComparators getFieldComparators()
-
hasComparatorForType
public boolean hasComparatorForType(java.lang.Class<?> keyType)
-
hasCustomComparators
public boolean hasCustomComparators()
-
getComparatorForType
public java.util.Comparator<?> getComparatorForType(java.lang.Class<?> fieldType)
-
hasCustomMessageForType
public boolean hasCustomMessageForType(java.lang.Class<?> fieldType)
-
getMessageForType
public java.lang.String getMessageForType(java.lang.Class<?> fieldType)
-
getTypeComparators
public TypeComparators getTypeComparators()
-
comparatorByTypes
java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>>> comparatorByTypes()
-
getIgnoreAllActualNullFields
public boolean getIgnoreAllActualNullFields()
-
getIgnoreAllExpectedNullFields
public boolean getIgnoreAllExpectedNullFields()
-
getIgnoreAllOverriddenEquals
public boolean getIgnoreAllOverriddenEquals()
-
setIgnoreAllActualEmptyOptionalFields
public void setIgnoreAllActualEmptyOptionalFields(boolean ignoringAllActualEmptyOptionalFields)
Sets whether actual empty optional fields are ignored in the recursive comparison.See
RecursiveComparisonAssert.ignoringActualNullFields()for code examples.- Parameters:
ignoringAllActualEmptyOptionalFields- whether to ignore actual empty optional fields in the recursive comparison
-
getIgnoreAllActualEmptyOptionalFields
public boolean getIgnoreAllActualEmptyOptionalFields()
-
setIgnoreAllActualNullFields
public void setIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)
Sets whether actual null fields are ignored in the recursive comparison.See
RecursiveComparisonAssert.ignoringActualNullFields()for code examples.- Parameters:
ignoreAllActualNullFields- whether to ignore actual null fields in the recursive comparison
-
setIgnoreAllExpectedNullFields
public void setIgnoreAllExpectedNullFields(boolean ignoreAllExpectedNullFields)
Sets whether expected null fields are ignored in the recursive comparison.See
RecursiveComparisonAssert.ignoringExpectedNullFields()for code examples.- Parameters:
ignoreAllExpectedNullFields- whether to ignore expected null fields in the recursive comparison
-
compareOnlyFields
public void compareOnlyFields(java.lang.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).The fields are specified by name, not by value, you can specify
person.namebut not"Jack"as"Jack"is not a field value.Specifying a field will make all its subfields to be compared, for example specifying
personwill lead to compareperson.name,person.address... on the other hand if you specifyperson.name,personwon't be compared butperson.namewill be.See
RecursiveComparisonAssert#comparingOnlyFields(String...)for examples.Note that the recursive comparison checks whether the fields actually exist and throws an
IllegalArgumentExceptionif some of them don't, this is done to catch typos.- Parameters:
fieldNamesToCompare- the fields of the object under test to compare in the comparison.
-
compareOnlyFieldsOfTypes
public void compareOnlyFieldsOfTypes(java.lang.Class<?>... typesToCompare)
Adds the given fields of types and their subfields to the set of fields from the object under test to compare (fields of other types will not be compared).Specifying a field of type will make all its subfields to be compared, for example specifying
Personwill lead to comparePerson.name,Person.address...See
RecursiveComparisonAssert#comparingOnlyFieldsOfTypes(Class...)for examples.- Parameters:
typesToCompare- the types to compare in the recursive comparison.
-
getComparedFields
public java.util.Set<FieldLocation> getComparedFields()
Returns the set of fields to compare from the object under test (no other fields will be compared).- Returns:
- the set of fields from the object under test to compare.
-
someComparedFieldsHaveBeenSpecified
boolean someComparedFieldsHaveBeenSpecified()
-
isOrIsChildOfAnyComparedFields
public boolean isOrIsChildOfAnyComparedFields(FieldLocation currentFieldLocation)
-
getComparedTypes
public java.util.Set<java.lang.Class<?>> getComparedTypes()
Returns the set of type to compare from the object under test (fields of other types will not be compared).- Returns:
- the set of types from the object under test to compare.
-
ignoreAllOverriddenEquals
public void ignoreAllOverriddenEquals()
Force a recursive comparison on all fields (except java types).See
RecursiveComparisonAssert.ignoringAllOverriddenEquals()for examples.
-
useOverriddenEquals
public void useOverriddenEquals()
Force a recursive comparison on all fields (except java types).See
RecursiveComparisonAssert.usingOverriddenEquals()for examples.
-
ignoreOverriddenEqualsForFields
public void ignoreOverriddenEqualsForFields(java.lang.String... fields)
Adds the given fields to the list of fields to force a recursive comparison on.See
RecursiveComparisonAssert#ignoringOverriddenEqualsForFields(String...)for examples.- Parameters:
fields- the fields to force a recursive comparison on.
-
ignoreOverriddenEqualsForFieldsMatchingRegexes
public void ignoreOverriddenEqualsForFieldsMatchingRegexes(java.lang.String... regexes)
Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.See
RecursiveComparisonAssert#ignoringOverriddenEqualsForFieldsMatchingRegexes(String...)for examples.- Parameters:
regexes- regexes used to specify the fields we want to force a recursive comparison on.
-
ignoreOverriddenEqualsForTypes
public void ignoreOverriddenEqualsForTypes(java.lang.Class<?>... types)
Adds the given types to the list of types to force a recursive comparison on.See
RecursiveComparisonAssert#ignoringOverriddenEqualsForTypes(Class...)for examples.- Parameters:
types- the types to the list of types to force a recursive comparison on.
-
getIgnoreCollectionOrder
public boolean getIgnoreCollectionOrder()
-
ignoreCollectionOrder
public void ignoreCollectionOrder(boolean ignoreCollectionOrder)
Sets whether to ignore collection order in the comparison.Important: ignoring collection order has a high performance cost because each element of the actual collection must be compared to each element of the expected collection which is a O(n²) operation. For example with a collection of 100 elements, the number of comparisons is 100x100 = 10 000!
See
RecursiveComparisonAssert.ignoringCollectionOrder()for code examples.- Parameters:
ignoreCollectionOrder- whether to ignore collection order in the comparison.
-
ignoreCollectionOrderInFields
public void ignoreCollectionOrderInFields(java.lang.String... fieldsToIgnoreCollectionOrder)
Adds the given fields to the list fields from the object under test to ignore collection order in the recursive comparison.Important: ignoring collection order has a high performance cost because each element of the actual collection must be compared to each element of the expected collection which is a O(n²) operation. For example with a collection of 100 elements, the number of comparisons is 100x100 = 10 000!
See
RecursiveComparisonAssert#ignoringCollectionOrderInFields(String...)for examples.- Parameters:
fieldsToIgnoreCollectionOrder- the fields of the object under test to ignore collection order in the comparison.
-
getIgnoredCollectionOrderInFields
public java.util.Set<java.lang.String> getIgnoredCollectionOrderInFields()
Returns the list fields from the object under test to ignore collection order in the recursive comparison.- Returns:
- the list fields from the object under test to ignore collection order in the recursive comparison.
-
ignoreCollectionOrderInFieldsMatchingRegexes
public void ignoreCollectionOrderInFieldsMatchingRegexes(java.lang.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.See
RecursiveComparisonAssert#ignoringCollectionOrderInFieldsMatchingRegexes(String...)for examples.- Parameters:
regexes- regexes used to find the object under test fields to ignore collection order in the comparison.
-
getIgnoredCollectionOrderInFieldsMatchingRegexes
public java.util.List<java.util.regex.Pattern> getIgnoredCollectionOrderInFieldsMatchingRegexes()
Returns the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.- Returns:
- the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.
-
registerComparatorForType
public <T> void registerComparatorForType(java.util.Comparator<? super T> comparator, java.lang.Class<T> type)Registers the givenComparatorto 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
Comparatorfor a given type will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert.withComparatorForType(Comparator, Class)for examples.- Type Parameters:
T- the class type to register a comparator for- Parameters:
comparator- theComparatorto use to compare the given typetype- the type to be compared with the given comparator.- Throws:
java.lang.NullPointerException- if the given comparator is null.
-
registerEqualsForType
public <T> void registerEqualsForType(java.util.function.BiPredicate<? super T,? super T> equals, java.lang.Class<T> type)Registers the givenBiPredicateto 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 withregisterComparatorForFields(Comparator, String...).Note that registering a
BiPredicatefor a given type will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert.withEqualsForType(BiPredicate, Class)for examples.- Type Parameters:
T- the class type to register a comparator for- Parameters:
equals- the equals implementation to compare the given typetype- the type to be compared with the given equals implementation .- Throws:
java.lang.NullPointerException- if the given BiPredicate is null.- Since:
- 3.17.0
-
registerComparatorForFields
public void registerComparatorForFields(java.util.Comparator<?> comparator, java.lang.String... fieldLocations)Registers the givenComparatorto compare the fields at the given locations.The fields must be specified from the root object, for example if
Foohas aBarfield and both have anidfield, one can register a comparator for Foo and Bar'sidby 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
Comparatorfor a given field will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert#withComparatorForFields(Comparator, String...)for examples.- Parameters:
comparator- theComparatorto use to compare the given fieldfieldLocations- the locations from the root object of the fields the comparator should be used for- Throws:
java.lang.NullPointerException- if the given comparator is null.
-
registerEqualsForFields
public void registerEqualsForFields(java.util.function.BiPredicate<?,?> equals, java.lang.String... fieldLocations)Registers the givenBiPredicateto compare the fields at the given locations.The fields must be specified from the root object, for example if
Foohas aBarfield and both have anidfield, one can register a BiPredicate for Foo and Bar'sidby 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 withregisterComparatorForType(Comparator, Class).Note that registering a
BiPredicatefor a given field will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert#withEqualsForFields(BiPredicate, String...)for examples.- Parameters:
equals- the equals implementation to compare the given fields.fieldLocations- the locations from the root object of the fields the comparator should be used for- Throws:
java.lang.NullPointerException- if the given BiPredicate is null.- Since:
- 3.17.0
-
registerEqualsForFieldsMatchingRegexes
public void registerEqualsForFieldsMatchingRegexes(java.util.function.BiPredicate<?,?> equals, java.lang.String... regexes)Allows to register aBiPredicateto compare fields whose location matches the given regexes. A typical usage is to compare double/float fields with a given precision.The fields are evaluated from the root object, for example if
Foohas aBarfield and both have anidfield, one can register a BiPredicate for Foo and Bar'sidby calling:
orregisterEqualsForFieldsMatchingRegexes(idBiPredicate, ".*id")registerEqualsForFieldsMatchingRegexes(idBiPredicate, "foo.*id")BiPredicates registered with this method have precedence over the ones registered with
registerEqualsForType(BiPredicate, Class)or the comparators registered withregisterComparatorForType(Comparator, Class)but don't have precedence over the ones registered with exact location match:registerEqualsForFields(BiPredicate, String...)orregisterComparatorForFields(Comparator, String...)If registered regexes for different
BiPredicatematch a given field, the latest registered regexesBiPredicatewins.Example: see
RecursiveComparisonAssert.withEqualsForFieldsMatchingRegexes(BiPredicate, String...)- Parameters:
equals- theBiPredicateto use to compare the fields matching the given regexesregexes- the regexes from the root object of the fields location the BiPredicate should be used for- Throws:
java.lang.NullPointerException- if the given BiPredicate is null.- Since:
- 3.24.0
-
registerErrorMessageForFields
public void registerErrorMessageForFields(java.lang.String message, java.lang.String... fieldLocations)Registers the giving message which would be shown when differences in the given fields while comparison occurred.The fields must be specified from the root object, for example if
Foohas aBarfield and both have anidfield, one can register a message for Foo and Bar'sidby 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
nullas message the default error message will be used (SeeComparisonDifference.DEFAULT_TEMPLATE).- Parameters:
message- the error message that will be thrown when comparison error occurredfieldLocations- the field locations the error message should be used for
-
registerErrorMessageForType
public void registerErrorMessageForType(java.lang.String message, java.lang.Class<?> clazz)Registers the giving message which would be shown when differences for the giving type while comparison occurred.Message registered with this method have less precedence than the ones registered with
registerErrorMessageForFields(String, String...).In case of
nullas message the default error message will be used (SeeComparisonDifference.DEFAULT_TEMPLATE).- Parameters:
message- the error message that will be thrown when comparison error occurredclazz- the type the error message should be used for
-
strictTypeChecking
public 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). Compatible means that the expected's type is the same or a subclass of actual's type.See
RecursiveComparisonAssert.withStrictTypeChecking()for code examples.- Parameters:
strictTypeChecking- whether the recursive comparison will check that actual's type is compatible with expected's type.
-
isInStrictTypeCheckingMode
public boolean isInStrictTypeCheckingMode()
-
getIgnoredOverriddenEqualsForTypes
public java.util.List<java.lang.Class<?>> getIgnoredOverriddenEqualsForTypes()
-
getIgnoredOverriddenEqualsForFields
public java.util.List<java.lang.String> getIgnoredOverriddenEqualsForFields()
-
getIgnoredOverriddenEqualsForFieldsMatchingRegexes
public java.util.List<java.util.regex.Pattern> getIgnoredOverriddenEqualsForFieldsMatchingRegexes()
-
comparatorByFields
public java.util.stream.Stream<java.util.Map.Entry<java.lang.String,java.util.Comparator<?>>> comparatorByFields()
-
getIntrospectionStrategy
public RecursiveComparisonIntrospectionStrategy getIntrospectionStrategy()
-
setIntrospectionStrategy
public void setIntrospectionStrategy(RecursiveComparisonIntrospectionStrategy introspectionStrategy)
Defines how objects are introspected in the recursive comparison.Default to
DefaultRecursiveComparisonIntrospectionStrategy.- Parameters:
introspectionStrategy- theRecursiveComparisonIntrospectionStrategyto use
-
allowComparingEnumAgainstString
public void allowComparingEnumAgainstString(boolean compareEnumAgainstString)
Allows the recursive comparison to compare an enum field against a string field.See
RecursiveComparisonAssert.withEnumStringComparison()for code examples.- Parameters:
compareEnumAgainstString- whether to allow the recursive comparison to compare enum field against string field.
-
isComparingEnumAgainstStringAllowed
public boolean isComparingEnumAgainstStringAllowed()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
multiLineDescription
public java.lang.String multiLineDescription(Representation representation)
-
shouldNotEvaluate
public boolean shouldNotEvaluate(DualValue dualValue)
-
shouldIgnore
public boolean shouldIgnore(DualValue dualValue)
-
shouldBeCompared
private boolean shouldBeCompared(DualValue dualValue)
-
matchesComparedField
private static java.util.function.Predicate<FieldLocation> matchesComparedField(FieldLocation field)
-
getActualChildrenNodeNamesToCompare
public java.util.Set<java.lang.String> getActualChildrenNodeNamesToCompare(DualValue dualValue)
-
getChildrenNodeNamesOf
java.util.Set<java.lang.String> getChildrenNodeNamesOf(java.lang.Object instance)
-
getValue
java.lang.Object getValue(java.lang.String name, java.lang.Object instance)
-
shouldIgnoreFieldBasedOnFieldValue
private boolean shouldIgnoreFieldBasedOnFieldValue(DualValue dualValue)
-
shouldIgnoreFieldBasedOnFieldLocation
private boolean shouldIgnoreFieldBasedOnFieldLocation(FieldLocation fieldLocation)
-
dualValueForField
private DualValue dualValueForField(DualValue parentDualValue, java.lang.String fieldName)
-
hasCustomComparator
boolean hasCustomComparator(DualValue dualValue)
-
shouldIgnoreOverriddenEqualsOf
public boolean shouldIgnoreOverriddenEqualsOf(DualValue dualValue)
-
shouldIgnoreOverriddenEqualsOf
public boolean shouldIgnoreOverriddenEqualsOf(java.lang.Class<?> clazz)
-
shouldIgnoreCollectionOrder
public boolean shouldIgnoreCollectionOrder(FieldLocation fieldLocation)
-
describeComparedFields
private void describeComparedFields(java.lang.StringBuilder description)
-
describeComparedTypes
private void describeComparedTypes(java.lang.StringBuilder description)
-
describeIgnoredTypes
private void describeIgnoredTypes(java.lang.StringBuilder description)
-
describeIgnoredTypesRegexes
private void describeIgnoredTypesRegexes(java.lang.StringBuilder description)
-
describeIgnoreAllActualNullFields
protected void describeIgnoreAllActualNullFields(java.lang.StringBuilder description)
-
describeIgnoreAllActualEmptyOptionalFields
protected void describeIgnoreAllActualEmptyOptionalFields(java.lang.StringBuilder description)
-
describeIgnoreAllExpectedNullFields
private void describeIgnoreAllExpectedNullFields(java.lang.StringBuilder description)
-
describeOverriddenEqualsMethodsUsage
private void describeOverriddenEqualsMethodsUsage(java.lang.StringBuilder description, Representation representation)
-
describeIgnoredOverriddenEqualsMethods
private void describeIgnoredOverriddenEqualsMethods(java.lang.StringBuilder description, Representation representation)
-
describeIgnoredOverriddenEqualsForTypes
private java.lang.String describeIgnoredOverriddenEqualsForTypes(Representation representation)
-
describeIgnoredOverriddenEqualsForFields
private java.lang.String describeIgnoredOverriddenEqualsForFields()
-
describeIgnoreCollectionOrder
private void describeIgnoreCollectionOrder(java.lang.StringBuilder description)
-
describeIgnoredCollectionOrderInFields
private void describeIgnoredCollectionOrderInFields(java.lang.StringBuilder description)
-
describeIgnoredCollectionOrderInFieldsMatchingRegexes
private void describeIgnoredCollectionOrderInFieldsMatchingRegexes(java.lang.StringBuilder description)
-
describeIntrospectionStrategy
private void describeIntrospectionStrategy(java.lang.StringBuilder description)
-
describeCompareEnumAgainstString
private void describeCompareEnumAgainstString(java.lang.StringBuilder description)
-
matchesAnIgnoredOverriddenEqualsRegex
private boolean matchesAnIgnoredOverriddenEqualsRegex(FieldLocation fieldLocation)
-
matchesAnIgnoredOverriddenEqualsType
private boolean matchesAnIgnoredOverriddenEqualsType(java.lang.Class<?> clazz)
-
matchesAnIgnoredOverriddenEqualsField
private boolean matchesAnIgnoredOverriddenEqualsField(DualValue dualValue)
-
matchesAnIgnoredNullField
private boolean matchesAnIgnoredNullField(DualValue dualValue)
-
matchesAnIgnoredEmptyOptionalField
private boolean matchesAnIgnoredEmptyOptionalField(DualValue dualValue)
-
matchesAnIgnoredFieldType
private boolean matchesAnIgnoredFieldType(DualValue dualValue)
-
matchesAnIgnoredType
private boolean matchesAnIgnoredType(java.lang.Object actual)
-
registerFieldLocationOfFieldsOfTypesToCompare
private void registerFieldLocationOfFieldsOfTypesToCompare(DualValue dualValue)
-
matchesAnIgnoredCollectionOrderInField
private boolean matchesAnIgnoredCollectionOrderInField(FieldLocation fieldLocation)
-
matchesAnIgnoredCollectionOrderInFieldRegex
private boolean matchesAnIgnoredCollectionOrderInFieldRegex(FieldLocation fieldLocation)
-
describeComparedFields
private java.lang.String describeComparedFields()
-
describeComparedTypes
private java.lang.String describeComparedTypes()
-
describeIgnoredCollectionOrderInFields
private java.lang.String describeIgnoredCollectionOrderInFields()
-
isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods
private boolean isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods()
-
describeRegisteredComparatorByTypes
private void describeRegisteredComparatorByTypes(java.lang.StringBuilder description)
-
describeComparatorForTypes
private void describeComparatorForTypes(java.lang.StringBuilder description)
-
formatRegisteredComparatorByType
private java.lang.String formatRegisteredComparatorByType(java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>> next)
-
describeRegisteredComparatorForFields
private void describeRegisteredComparatorForFields(java.lang.StringBuilder description)
-
describeComparatorForFields
private void describeComparatorForFields(java.lang.StringBuilder description)
-
describeComparatorForRegexFields
private void describeComparatorForRegexFields(java.lang.StringBuilder description)
-
formatRegisteredComparatorForField
private java.lang.String formatRegisteredComparatorForField(java.util.Map.Entry<java.lang.String,java.util.Comparator<?>> comparatorForField)
-
formatRegisteredComparatorForRegexFields
private java.lang.String formatRegisteredComparatorForRegexFields(java.util.Map.Entry<java.util.List<java.util.regex.Pattern>,java.util.Comparator<?>> comparatorForRegexFields)
-
describeTypeCheckingStrictness
private void describeTypeCheckingStrictness(java.lang.StringBuilder description)
-
describeRegisteredErrorMessagesForFields
private void describeRegisteredErrorMessagesForFields(java.lang.StringBuilder description)
-
describeErrorMessagesForFields
private void describeErrorMessagesForFields(java.lang.StringBuilder description)
-
describeRegisteredErrorMessagesForTypes
private void describeRegisteredErrorMessagesForTypes(java.lang.StringBuilder description)
-
describeErrorMessagesForType
private void describeErrorMessagesForType(java.lang.StringBuilder description)
-
builder
public static RecursiveComparisonConfiguration.Builder builder()
Creates builder to buildRecursiveComparisonConfiguration.- Returns:
- created builder
-
checkComparedFieldsExist
void checkComparedFieldsExist(java.lang.Object actual)
-
checkComparedFieldExists
private java.util.Optional<java.util.Map.Entry<FieldLocation,java.lang.String>> checkComparedFieldExists(java.lang.Object actual, FieldLocation comparedFieldLocation)
-
formatUnknownComparedField
private static java.lang.String formatUnknownComparedField(FieldLocation fieldLocation, java.lang.String unknownNodeNameElement)
-
hierarchyMatchesAnyComparedTypes
boolean hierarchyMatchesAnyComparedTypes(DualValue dualValue)
-
matchesOrIsChildOfFieldMatchingAnyComparedTypes
boolean matchesOrIsChildOfFieldMatchingAnyComparedTypes(DualValue dualValue)
-
hasComparedTypes
boolean hasComparedTypes()
-
isFieldOfTypeToCompare
private boolean isFieldOfTypeToCompare(DualValue dualValue)
-
exactlyMatchesAnyComparedFields
boolean exactlyMatchesAnyComparedFields(DualValue dualValue)
-
toComparator
private static java.util.Comparator toComparator(java.util.function.BiPredicate equals)
-
-