Class RecursiveComparisonConfiguration
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder 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
FieldsModifier and TypeFieldDescriptionstatic final DefaultRecursiveComparisonIntrospectionStrategystatic final StringFields inherited from class org.assertj.core.api.recursive.AbstractRecursiveOperationConfiguration
DEFAULT_DELIMITER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidallowComparingEnumAgainstString(boolean compareEnumAgainstString) Allows the recursive comparison to compare an enum field against a string field.builder()Creates builder to buildRecursiveComparisonConfiguration.Stream<Map.Entry<String, Comparator<?>>> voidcompareOnlyFields(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(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).protected voiddescribeIgnoreAllActualEmptyOptionalFields(StringBuilder description) protected voiddescribeIgnoreAllActualNullFields(StringBuilder description) booleangetActualChildrenNodeNamesToCompare(DualValue dualValue) Comparator<?> getComparatorForField(String fieldName) Comparator<?> getComparatorForType(Class<?> fieldType) Returns the set of fields to compare from the object under test (no other fields will be compared).Returns the set of type to compare from the object under test (fields of other types will not be compared).booleanbooleanbooleanbooleanbooleanReturns the list fields from the object under test 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.getMessageForField(String fieldName) getMessageForType(Class<?> fieldType) booleanhasComparatorForField(String fieldName) booleanhasComparatorForType(Class<?> keyType) booleanbooleanhasCustomMessageForField(String fieldName) booleanhasCustomMessageForType(Class<?> fieldType) inthashCode()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 fields from the object under test 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.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.booleanbooleanbooleanisOrIsChildOfAnyComparedFields(FieldLocation currentFieldLocation) 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.voidregisterEqualsForFieldsMatchingRegexes(BiPredicate<?, ?> equals, String... regexes) Allows to register aBiPredicateto compare fields whose location matches the given regexes.<T> voidregisterEqualsForType(BiPredicate<? super T, ? super T> equals, Class<T> type) Registers the givenBiPredicateto compare the fields with the given type.voidregisterErrorMessageForFields(String message, String... fieldLocations) Registers the giving message which would be shown when differences in the given fields while comparison occurred.voidregisterErrorMessageForType(String message, Class<?> clazz) Registers the giving message which would be shown when differences for the giving type while comparison occurred.voidvoidsetIgnoreAllActualEmptyOptionalFields(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.booleanshouldIgnore(DualValue dualValue) booleanshouldIgnoreCollectionOrder(FieldLocation fieldLocation) booleanshouldIgnoreOverriddenEqualsOf(Class<?> clazz) booleanshouldIgnoreOverriddenEqualsOf(DualValue dualValue) booleanshouldNotEvaluate(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).toString()voidForce 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 Details
-
INDENT_LEVEL_2
- See Also:
-
DEFAULT_RECURSIVE_COMPARISON_INTROSPECTION_STRATEGY
public static final DefaultRecursiveComparisonIntrospectionStrategy DEFAULT_RECURSIVE_COMPARISON_INTROSPECTION_STRATEGY
-
-
Constructor Details
-
RecursiveComparisonConfiguration
-
RecursiveComparisonConfiguration
public RecursiveComparisonConfiguration()
-
-
Method Details
-
registerFieldLocationToCompareBecauseOfTypesToCompare
-
getRepresentation
-
hasComparatorForField
-
getComparatorForField
-
hasCustomMessageForField
-
getMessageForField
-
getFieldComparators
-
hasComparatorForType
-
hasCustomComparators
public boolean hasCustomComparators() -
getComparatorForType
-
hasCustomMessageForType
-
getMessageForType
-
getTypeComparators
-
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
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
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
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.
-
isOrIsChildOfAnyComparedFields
-
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
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
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
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
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
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
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
-
registerEqualsForFieldsMatchingRegexes
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:
NullPointerException- if the given BiPredicate is null.- Since:
- 3.24.0
-
registerErrorMessageForFields
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
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
-
getIgnoredOverriddenEqualsForFields
-
getIgnoredOverriddenEqualsForFieldsMatchingRegexes
-
comparatorByFields
-
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
-
hashCode
public int hashCode() -
equals
-
multiLineDescription
-
shouldNotEvaluate
-
shouldIgnore
-
getActualChildrenNodeNamesToCompare
-
shouldIgnoreOverriddenEqualsOf
-
shouldIgnoreOverriddenEqualsOf
-
shouldIgnoreCollectionOrder
-
describeIgnoreAllActualNullFields
-
describeIgnoreAllActualEmptyOptionalFields
-
builder
Creates builder to buildRecursiveComparisonConfiguration.- Returns:
- created builder
-