Class RecursiveComparisonConfiguration.Builder
- Enclosing class:
- RecursiveComparisonConfiguration
RecursiveComparisonConfiguration
.-
Method Summary
Modifier and TypeMethodDescriptionbuild()
withComparatorForFields
(Comparator<?> comparator, String... fields) Registers the givenComparator
to compare the fields at the given locations.withComparatorForType
(Comparator<? super T> comparator, Class<T> type) Registers the givenComparator
to compare the fields with the given type.withComparedFields
(String... fieldsToCompare) Adds the given fields to the set of fields from the object under test to compare in the recursive comparison.withComparedTypes
(Class<?>... comparedTypes) Adds the given types to the set of fields from the object under test to compare in the recursive comparison.withEqualsForFields
(BiPredicate<?, ?> equals, String... fields) Registers the givenBiPredicate
to compare the fields at the given locations.withEqualsForFieldsMatchingRegexes
(BiPredicate<?, ?> equals, String... regexes) Allows to register aBiPredicate
to compare fields whose location matches the given regexes.withEqualsForType
(BiPredicate<? super T, ? super T> equals, Class<T> type) Registers the givenBiPredicate
to compare the fields with the given type.withErrorMessageForFields
(String message, String... fields) Registers the giving message which would be shown when differences in the given fields while comparison occurred.withErrorMessageForType
(String message, Class<?> type) Registers the giving message which would be shown when differences for the giving type while comparison occurred.withIgnoreAllActualEmptyOptionalFields
(boolean ignoreAllActualEmptyOptionalFields) Sets whether actual empty optional fields are ignored in the recursive comparison.withIgnoreAllActualNullFields
(boolean ignoreAllActualNullFields) Sets whether actual null fields are ignored in the recursive comparison.withIgnoreAllExpectedNullFields
(boolean ignoreAllExpectedNullFields) Sets whether expected null fields are ignored in the recursive comparison.withIgnoreAllOverriddenEquals
(boolean ignoreAllOverriddenEquals) Force a recursive comparison on all fields (except java types) if true.withIgnoreCollectionOrder
(boolean ignoreCollectionOrder) Sets whether to ignore collection order in the comparison.withIgnoredCollectionOrderInFields
(String... fieldsToIgnoreCollectionOrder) Adds the given fields to the list fields from the object under test to ignore collection order in the recursive comparison.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.withIgnoredFields
(String... fieldsToIgnore) Adds the given fields to the set of fields from the object under test to ignore in the recursive comparison.withIgnoredFieldsMatchingRegexes
(String... regexes) Allows to ignore in the recursive comparison the object under test fields matching the given regexes.withIgnoredFieldsOfTypes
(Class<?>... types) Adds the given types to the list fields from the object under test types to ignore in the recursive comparison.withIgnoredOverriddenEqualsForFields
(String... fields) Adds the given fields to the list of fields to force a recursive comparison on.Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.withIgnoredOverriddenEqualsForTypes
(Class<?>... types) Adds the given types to the list of types to force a recursive comparison on.withIntrospectionStrategy
(RecursiveComparisonIntrospectionStrategy introspectionStrategy) Defines how objects are introspected in the recursive comparison.withStrictTypeChecking
(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).
-
Method Details
-
withStrictTypeChecking
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.- Returns:
- this builder.
-
withIgnoreAllActualNullFields
public RecursiveComparisonConfiguration.Builder withIgnoreAllActualNullFields(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- Returns:
- this builder.
-
withIgnoreAllActualEmptyOptionalFields
public RecursiveComparisonConfiguration.Builder withIgnoreAllActualEmptyOptionalFields(boolean ignoreAllActualEmptyOptionalFields) Sets whether actual empty optional fields are ignored in the recursive comparison.See
RecursiveComparisonAssert.ignoringActualEmptyOptionalFields()
for code examples.- Parameters:
ignoreAllActualEmptyOptionalFields
- whether to ignore actual empty optional fields in the recursive comparison- Returns:
- this builder.
-
withIgnoreAllExpectedNullFields
public RecursiveComparisonConfiguration.Builder withIgnoreAllExpectedNullFields(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- Returns:
- this builder.
-
withComparedFields
Adds the given fields to the set of fields from the object under test to compare in the recursive comparison.Nested fields can be specified like this: home.address.street.
See
RecursiveComparisonAssert.comparingOnlyFields(String...)
for examples.- Parameters:
fieldsToCompare
- the fields of the object under test to compare.- Returns:
- this builder.
-
withComparedTypes
Adds the given types to the set of fields from the object under test to compare in the recursive comparison. SeeRecursiveComparisonAssert.comparingOnlyFieldsOfTypes(Class[])
(String...)} for examples.- Parameters:
comparedTypes
- the types to compare in the recursive comparison..- Returns:
- this builder.
-
withIgnoredOverriddenEqualsForTypes
public RecursiveComparisonConfiguration.Builder withIgnoredOverriddenEqualsForTypes(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.- Returns:
- this builder.
-
withIgnoredOverriddenEqualsForFields
public RecursiveComparisonConfiguration.Builder withIgnoredOverriddenEqualsForFields(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.- Returns:
- this builder.
-
withIgnoredOverriddenEqualsForFieldsMatchingRegexes
public RecursiveComparisonConfiguration.Builder withIgnoredOverriddenEqualsForFieldsMatchingRegexes(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.- Returns:
- this builder.
-
withIgnoreAllOverriddenEquals
public RecursiveComparisonConfiguration.Builder withIgnoreAllOverriddenEquals(boolean ignoreAllOverriddenEquals) Force a recursive comparison on all fields (except java types) if true.See
RecursiveComparisonAssert.ignoringAllOverriddenEquals()
for examples.- Parameters:
ignoreAllOverriddenEquals
- whether to force a recursive comparison on all fields (except java types) or not.- Returns:
- this builder.
-
withIgnoreCollectionOrder
public RecursiveComparisonConfiguration.Builder withIgnoreCollectionOrder(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.- Returns:
- this builder.
-
withIgnoredCollectionOrderInFields
public RecursiveComparisonConfiguration.Builder withIgnoredCollectionOrderInFields(String... fieldsToIgnoreCollectionOrder) Adds the given fields to the list fields from the object under test 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.- Returns:
- this builder.
-
withIgnoredCollectionOrderInFieldsMatchingRegexes
public RecursiveComparisonConfiguration.Builder withIgnoredCollectionOrderInFieldsMatchingRegexes(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.- Returns:
- this builder.
-
withComparatorForType
public <T> RecursiveComparisonConfiguration.Builder withComparatorForType(Comparator<? super T> comparator, Class<T> type) Registers the givenComparator
to compare the fields with the given type.Comparators registered with this method have less precedence than comparators registered with
withComparatorForFields(Comparator, String...)
or BiPredicate registered withwithEqualsForFields(BiPredicate, 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.- Type Parameters:
T
- the class type to register a comparator for- Parameters:
comparator
- theComparator
to use to compare the given fieldtype
- the type to be compared with the given comparator.- Returns:
- this builder.
- Throws:
NullPointerException
- if the given Comparator is null.
-
withEqualsForType
public <T> RecursiveComparisonConfiguration.Builder withEqualsForType(BiPredicate<? super T, ? super T> equals, Class<T> type) Registers the givenBiPredicate
to compare the fields with the given type.BiPredicates registered with this method have less precedence than the ones registered with
withEqualsForFields(BiPredicate, String...)
or the comparators registered withwithComparatorForFields(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.- Type Parameters:
T
- the class type to register a BiPredicate for- Parameters:
equals
- theBiPredicate
to use to compare the given fieldtype
- the type to be compared with the given comparator.- Returns:
- this builder.
- Throws:
NullPointerException
- if the given BiPredicate is null.- Since:
- 3.17.0
-
withComparatorForFields
public RecursiveComparisonConfiguration.Builder withComparatorForFields(Comparator<?> comparator, String... fields) Registers the givenComparator
to compare the fields at the given locations.The fields must be specified from the root object, for example if
Foo
has aBar
field and both have anid
field, one can register a comparator for Foo and Bar'sid
by calling:registerComparatorForFields(idComparator, "foo.id", "foo.bar.id")
Comparators registered with this method have precedence over comparators registered with
withComparatorForType(Comparator, Class)
or BiPredicate registered withwithEqualsForType(BiPredicate, Class)
.Note that registering a
Comparator
for a given field will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert#withComparatorForFields(Comparator comparator, String...fields)
for examples.- Parameters:
comparator
- theComparator
to use to compare the given fieldfields
- the fields the comparator should be used for- Returns:
- this builder.
- Throws:
NullPointerException
- if the given Comparator is null.
-
withEqualsForFields
public RecursiveComparisonConfiguration.Builder withEqualsForFields(BiPredicate<?, ?> equals, String... fields) Registers the givenBiPredicate
to compare the fields at the given locations.The fields must be specified from the root object, for example if
Foo
has aBar
field and both have anid
field, one can register a BiPredicate for Foo and Bar'sid
by calling:withEqualsForFields(idBiPredicate, "foo.id", "foo.bar.id")
BiPredicates registered with this method have precedence over the ones registered with
withEqualsForType(BiPredicate, Class)
or the comparators registered withwithComparatorForType(Comparator, Class)
.Note that registering a
BiPredicate
for a given field will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert#withEqualsForFields(BiPredicate equals, String...fields)
for examples.- Parameters:
equals
- theBiPredicate
to use to compare the given fieldsfields
- the fields the BiPredicate should be used for- Returns:
- this builder.
- Throws:
NullPointerException
- if the given BiPredicate is null.- Since:
- 3.17.0
-
withEqualsForFieldsMatchingRegexes
public RecursiveComparisonConfiguration.Builder withEqualsForFieldsMatchingRegexes(BiPredicate<?, ?> equals, String... regexes) Allows to register aBiPredicate
to 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
Foo
has aBar
field and both have anid
field, one can register a BiPredicate for Foo and Bar'sid
by calling:
orwithEqualsForFields(idBiPredicate, ".*id")
withEqualsForFields(idBiPredicate, "foo.*id")
BiPredicates registered with this method have precedence over the ones registered with
RecursiveComparisonConfiguration.registerEqualsForType(BiPredicate, Class)
or the comparators registered withRecursiveComparisonConfiguration.registerComparatorForType(Comparator, Class)
but don't have precedence over the ones registered with exact location match:RecursiveComparisonConfiguration.registerEqualsForFields(BiPredicate, String...)
orRecursiveComparisonConfiguration.registerComparatorForFields(Comparator, String...)
If registered regexes for different
BiPredicate
match a given field, the latest registered regexesBiPredicate
wins.See
RecursiveComparisonAssert#withEqualsForFieldsMatchingRegexes(BiPredicate equals, String...fields)
for examples.- Parameters:
equals
- theBiPredicate
to use to compare the fields matching the given regexesregexes
- the regexes to match fields against- Returns:
- this builder.
- Throws:
NullPointerException
- if the given BiPredicate is null.- Since:
- 3.24.0
-
withErrorMessageForFields
public RecursiveComparisonConfiguration.Builder withErrorMessageForFields(String message, String... fields) 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
Foo
has aBar
field and both have anid
field, one can register a message for Foo and Bar'sid
by calling:withErrorMessageForFields("some message", "foo.id", "foo.bar.id")
Messages registered with this method have precedence over the ones registered with
withErrorMessageForType(String, Class)
.In case of
null
as message the default error message will be used (SeeComparisonDifference.DEFAULT_TEMPLATE
).- Parameters:
message
- the error message that will be thrown when comparison error occurred.fields
- the fields the error message should be used for.- Returns:
- this builder.
- Throws:
NullPointerException
- if the giving list of arguments is null.
-
withErrorMessageForType
public RecursiveComparisonConfiguration.Builder withErrorMessageForType(String message, Class<?> type) 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
withErrorMessageForFields(String, String...)
.In case of
null
as message the default error message will be used (SeeComparisonDifference.DEFAULT_TEMPLATE
).- Parameters:
message
- the error message that will be thrown when comparison error occurredtype
- the type the error message should be used for- Returns:
- this builder
-
withIgnoredFields
Adds the given fields to the set of fields from the object under test to ignore in the recursive comparison. Nested fields can be specified like this: home.address.street.See
RecursiveComparisonAssert#ignoringFields(String...)
for examples.- Parameters:
fieldsToIgnore
- the fields of the object under test to ignore in the comparison.- Returns:
- this builder.
-
withIgnoredFieldsMatchingRegexes
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.- Returns:
- this builder.
-
withIgnoredFieldsOfTypes
Adds the given types to the list fields from the object under test 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.- Returns:
- this builder.
-
withIntrospectionStrategy
public RecursiveComparisonConfiguration.Builder withIntrospectionStrategy(RecursiveComparisonIntrospectionStrategy introspectionStrategy) Defines how objects are introspected in the recursive comparison.Default to
DefaultRecursiveComparisonIntrospectionStrategy
.- Parameters:
introspectionStrategy
- theRecursiveComparisonIntrospectionStrategy
to use- Returns:
- This builder.
-
build
-