Class RecursiveComparisonConfiguration
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder to buildRecursiveComparisonConfiguration. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FieldComparatorsprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanstatic final Stringprivate booleanprivate TypeComparators -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate -
Method Summary
Modifier and TypeMethodDescriptionprivate static Class<?>asWrapperIfPrimitiveType(Class<?> type) builder()Creates builder to buildRecursiveComparisonConfiguration.Stream<Map.Entry<String,Comparator<?>>> (package private) Stream<Map.Entry<Class<?>,Comparator<?>>> private voiddescribeComparatorForFields(StringBuilder description) private voiddescribeComparatorForTypes(StringBuilder description) private voiddescribeIgnoreAllActualEmptyOptionalFields(StringBuilder description) private voiddescribeIgnoreAllActualNullFields(StringBuilder description) private voiddescribeIgnoreAllExpectedNullFields(StringBuilder description) private voiddescribeIgnoreCollectionOrder(StringBuilder description) private Stringprivate voiddescribeIgnoredCollectionOrderInFields(StringBuilder description) private voidprivate Stringprivate voiddescribeIgnoredFields(StringBuilder description) private voiddescribeIgnoredFieldsForTypes(StringBuilder description) private voiddescribeIgnoredFieldsRegexes(StringBuilder description) private Stringprivate StringdescribeIgnoredOverriddenEqualsForTypes(Representation representation) private voiddescribeIgnoredOverriddenEqualsMethods(StringBuilder description, Representation representation) private Stringprivate voiddescribeOverriddenEqualsMethodsUsage(StringBuilder description, Representation representation) private StringdescribeRegexes(List<Pattern> regexes) private voiddescribeRegisteredComparatorByTypes(StringBuilder description) private voiddescribeRegisteredComparatorForFields(StringBuilder description) private voiddescribeTypeCheckingStrictness(StringBuilder description) private static DualValuedualValueForField(DualValue parentDualValue, String fieldName) booleanprivate StringformatRegisteredComparatorByType(Map.Entry<Class<?>, Comparator<?>> next) private StringformatRegisteredComparatorForField(Map.Entry<String, Comparator<?>> comparatorForField) Comparator<?>getComparatorForField(String fieldName) Comparator<?>getComparatorForType(Class<?> fieldType) (package private) boolean(package private) boolean(package private) boolean(package private) boolean(package private) booleanReturns the list of 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.Returns the list of the object under test fields to ignore in the recursive comparison.Returns the set of the object under test fields types to ignore in the recursive comparison.getNonIgnoredActualFieldNames(DualValue dualValue) booleanhasComparatorForField(String fieldName) booleanhasComparatorForType(Class<?> keyType) (package private) booleanhasCustomComparator(DualValue dualValue) booleaninthashCode()voidForce a recursive comparison on all fields (except java types).voidignoreCollectionOrder(boolean ignoreCollectionOrder) Sets whether to ignore collection order in the comparison.voidignoreCollectionOrderInFields(String... fieldsToIgnoreCollectionOrder) Adds the given fields to the list of the object under test fields to ignore collection order in the recursive comparison.voidignoreCollectionOrderInFieldsMatchingRegexes(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.voidignoreFields(String... fieldsToIgnore) Adds the given fields to the list of the object under test fields to ignore in the recursive comparison.voidignoreFieldsMatchingRegexes(String... regexes) Allows to ignore in the recursive comparison the object under test fields matching the given regexes.voidignoreFieldsOfTypes(Class<?>... types) Adds the given types to the list of the object under test fields types to ignore in the recursive comparison.voidignoreOverriddenEqualsForFields(String... fields) Adds the given fields to the list of fields to force a recursive comparison on.voidignoreOverriddenEqualsForFieldsMatchingRegexes(String... regexes) Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.voidignoreOverriddenEqualsForTypes(Class<?>... types) Adds the given types to the list of types to force a recursive comparison on.private booleanbooleanprivate booleanmatchesAnIgnoredCollectionOrderInField(FieldLocation fieldLocation) private booleanmatchesAnIgnoredCollectionOrderInFieldRegex(FieldLocation fieldLocation) private booleanmatchesAnIgnoredEmptyOptionalField(DualValue dualValue) private booleanmatchesAnIgnoredField(FieldLocation fieldLocation) private booleanmatchesAnIgnoredFieldRegex(FieldLocation fieldLocation) private booleanmatchesAnIgnoredFieldType(DualValue dualValue) private booleanmatchesAnIgnoredNullField(DualValue dualValue) private booleanmatchesAnIgnoredOverriddenEqualsField(FieldLocation fieldLocation) private booleanmatchesAnIgnoredOverriddenEqualsRegex(Class<?> clazz) private booleanmatchesAnIgnoredOverriddenEqualsType(Class<?> clazz) multiLineDescription(Representation representation) voidregisterComparatorForFields(Comparator<?> comparator, String... fieldLocations) Registers the givenComparatorto compare the fields at the given locations.<T> voidregisterComparatorForType(Comparator<? super T> comparator, Class<T> type) Registers the givenComparatorto compare the fields with the given type.voidregisterEqualsForFields(BiPredicate<?, ?> equals, String... fieldLocations) Registers the givenBiPredicateto compare the fields at the given locations.<T> voidregisterEqualsForType(BiPredicate<? super T, ? super T> equals, Class<T> type) Registers the givenBiPredicateto compare the fields with the given type.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.(package private) booleanshouldIgnore(DualValue dualValue) (package private) booleanshouldIgnoreCollectionOrder(FieldLocation fieldLocation) private booleanshouldIgnoreFieldBasedOnFieldLocation(FieldLocation fieldLocation) private booleanshouldIgnoreFieldBasedOnFieldValue(DualValue dualValue) (package private) booleanshouldIgnoreOverriddenEqualsOf(Class<? extends Object> clazz) (package private) booleanshouldIgnoreOverriddenEqualsOf(DualValue dualValue) 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 ComparatortoComparator(BiPredicate equals) toString()voidForce a recursive comparison on all fields (except java types).
-
Field Details
-
INDENT_LEVEL_2
- See Also:
-
strictTypeChecking
private boolean strictTypeChecking -
ignoreAllActualNullFields
private boolean ignoreAllActualNullFields -
ignoreAllActualEmptyOptionalFields
private boolean ignoreAllActualEmptyOptionalFields -
ignoreAllExpectedNullFields
private boolean ignoreAllExpectedNullFields -
ignoredFields
-
ignoredFieldsRegexes
-
ignoredTypes
-
ignoredOverriddenEqualsForTypes
-
ignoredOverriddenEqualsForFields
-
ignoredOverriddenEqualsForFieldsMatchingRegexes
-
ignoreAllOverriddenEquals
private boolean ignoreAllOverriddenEquals -
ignoreCollectionOrder
private boolean ignoreCollectionOrder -
ignoredCollectionOrderInFields
-
ignoredCollectionOrderInFieldsMatchingRegexes
-
typeComparators
-
fieldComparators
-
-
Constructor Details
-
RecursiveComparisonConfiguration
-
RecursiveComparisonConfiguration
public RecursiveComparisonConfiguration()
-
-
Method Details
-
hasComparatorForField
-
getComparatorForField
-
getFieldComparators
-
hasComparatorForType
-
hasCustomComparators
public boolean hasCustomComparators() -
getComparatorForType
-
getTypeComparators
-
comparatorByTypes
Stream<Map.Entry<Class<?>,Comparator<?>>> comparatorByTypes() -
getIgnoreAllActualNullFields
boolean getIgnoreAllActualNullFields() -
getIgnoreAllExpectedNullFields
boolean getIgnoreAllExpectedNullFields() -
getIgnoreAllOverriddenEquals
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
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
-
ignoreFields
Adds the given fields to the list of the object under test fields to ignore in the recursive comparison.The field are ignored by name, not by value.
See
RecursiveComparisonAssert#ignoringFields(String...)for examples.- Parameters:
fieldsToIgnore- the fields of the object under test to ignore in the comparison.
-
ignoreFieldsMatchingRegexes
Allows to ignore in the recursive comparison the object under test fields matching the given regexes. The given regexes are added to the already registered ones.See
RecursiveComparisonAssert#ignoringFieldsMatchingRegexes(String...)for examples.- Parameters:
regexes- regexes used to ignore fields in the comparison.
-
ignoreFieldsOfTypes
Adds the given types to the list of the object under test fields types to ignore in the recursive comparison. The fields are ignored if their types exactly match one of the ignored types, if a field is a subtype of an ignored type it won't be ignored.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.- Parameters:
types- the types of the object under test to ignore in the comparison.
-
asWrapperIfPrimitiveType
-
getIgnoredFields
Returns the list of the object under test fields to ignore in the recursive comparison.- Returns:
- the list of the object under test fields to ignore in the recursive comparison.
-
getIgnoredTypes
Returns the set of the object under test fields types to ignore in the recursive comparison.- Returns:
- the set of the object under test fields types to ignore in the recursive comparison.
-
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
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
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
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
boolean getIgnoreCollectionOrder() -
ignoreCollectionOrder
public void ignoreCollectionOrder(boolean ignoreCollectionOrder) Sets whether to ignore collection order in the comparison.See
RecursiveComparisonAssert.ignoringCollectionOrder()for code examples.- Parameters:
ignoreCollectionOrder- whether to ignore collection order in the comparison.
-
ignoreCollectionOrderInFields
Adds the given fields to the list of the object under test fields to ignore collection order in the recursive comparison.See
RecursiveComparisonAssert#ignoringCollectionOrderInFields(String...)for examples.- Parameters:
fieldsToIgnoreCollectionOrder- the fields of the object under test to ignore collection order in the comparison.
-
getIgnoredCollectionOrderInFields
Returns the list of the object under test fields to ignore collection order in the recursive comparison.- Returns:
- the list of the object under test fields to ignore collection order in the recursive comparison.
-
ignoreCollectionOrderInFieldsMatchingRegexes
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 in the comparison.
-
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
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:
NullPointerException- if the given comparator is null.
-
registerEqualsForType
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:
NullPointerException- if the given BiPredicate is null.- Since:
- 3.17.0
-
registerComparatorForFields
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:
NullPointerException- if the given comparator is null.
-
registerEqualsForFields
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:
NullPointerException- if the given BiPredicate is null.- Since:
- 3.17.0
-
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() -
getIgnoredFieldsRegexes
-
getIgnoredOverriddenEqualsForTypes
-
getIgnoredOverriddenEqualsForFields
-
getIgnoredOverriddenEqualsForFieldsMatchingRegexes
-
comparatorByFields
-
toString
-
hashCode
public int hashCode() -
equals
-
multiLineDescription
-
shouldIgnore
-
getNonIgnoredActualFieldNames
-
shouldIgnoreFieldBasedOnFieldValue
-
shouldIgnoreFieldBasedOnFieldLocation
-
dualValueForField
-
hasCustomComparator
-
shouldIgnoreOverriddenEqualsOf
-
shouldIgnoreOverriddenEqualsOf
-
shouldIgnoreCollectionOrder
-
describeIgnoredFieldsRegexes
-
describeIgnoredFields
-
describeIgnoredFieldsForTypes
-
describeIgnoreAllActualNullFields
-
describeIgnoreAllActualEmptyOptionalFields
-
describeIgnoreAllExpectedNullFields
-
describeOverriddenEqualsMethodsUsage
private void describeOverriddenEqualsMethodsUsage(StringBuilder description, Representation representation) -
describeIgnoredOverriddenEqualsMethods
private void describeIgnoredOverriddenEqualsMethods(StringBuilder description, Representation representation) -
describeIgnoredOverriddenEqualsForTypes
-
describeIgnoredOverriddenEqualsForFields
-
describeIgnoreCollectionOrder
-
describeIgnoredCollectionOrderInFields
-
describeIgnoredCollectionOrderInFieldsMatchingRegexes
-
matchesAnIgnoredOverriddenEqualsRegex
-
matchesAnIgnoredOverriddenEqualsType
-
matchesAnIgnoredOverriddenEqualsField
-
matchesAnIgnoredNullField
-
matchesAnIgnoredEmptyOptionalField
-
matchesAnIgnoredFieldRegex
-
matchesAnIgnoredFieldType
-
matchesAnIgnoredField
-
matchesAnIgnoredCollectionOrderInField
-
matchesAnIgnoredCollectionOrderInFieldRegex
-
describeIgnoredFields
-
describeIgnoredTypes
-
describeIgnoredCollectionOrderInFields
-
describeRegexes
-
isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods
private boolean isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods() -
describeRegisteredComparatorByTypes
-
describeComparatorForTypes
-
formatRegisteredComparatorByType
-
describeRegisteredComparatorForFields
-
describeComparatorForFields
-
formatRegisteredComparatorForField
private String formatRegisteredComparatorForField(Map.Entry<String, Comparator<?>> comparatorForField) -
describeTypeCheckingStrictness
-
builder
Creates builder to buildRecursiveComparisonConfiguration.- Returns:
- created builder
-
toComparator
-