Class RecursiveComparisonConfiguration.Builder
- java.lang.Object
-
- org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration.Builder
-
- Enclosing class:
- RecursiveComparisonConfiguration
public static final class RecursiveComparisonConfiguration.Builder extends Object
Builder to buildRecursiveComparisonConfiguration.
-
-
Field Summary
Fields Modifier and Type Field Description private String[]comparedFieldsprivate FieldComparatorsfieldComparatorsprivate FieldMessagesfieldMessagesprivate booleanignoreAllActualEmptyOptionalFieldsprivate booleanignoreAllActualNullFieldsprivate booleanignoreAllExpectedNullFieldsprivate booleanignoreAllOverriddenEqualsprivate booleanignoreCollectionOrderprivate String[]ignoredCollectionOrderInFieldsprivate String[]ignoredCollectionOrderInFieldsMatchingRegexesprivate String[]ignoredFieldsprivate String[]ignoredFieldsMatchingRegexesprivate String[]ignoredOverriddenEqualsForFieldsprivate String[]ignoredOverriddenEqualsForFieldsMatchingRegexesprivate Class<?>[]ignoredOverriddenEqualsForTypesprivate Class<?>[]ignoredTypesprivate booleanstrictTypeCheckingprivate org.assertj.core.internal.TypeComparatorstypeComparatorsprivate org.assertj.core.internal.TypeMessagestypeMessages
-
Constructor Summary
Constructors Modifier Constructor Description privateBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RecursiveComparisonConfigurationbuild()RecursiveComparisonConfiguration.BuilderwithComparatorForFields(Comparator<?> comparator, String... fields)Registers the givenComparatorto compare the fields at the given locations.<T> RecursiveComparisonConfiguration.BuilderwithComparatorForType(Comparator<? super T> comparator, Class<T> type)Registers the givenComparatorto compare the fields with the given type.RecursiveComparisonConfiguration.BuilderwithComparedFields(String... fieldsToCompare)Adds the given fields to the set of fields from the object under test to compare in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithEqualsForFields(BiPredicate<?,?> equals, String... fields)Registers the givenBiPredicateto compare the fields at the given locations.<T> RecursiveComparisonConfiguration.BuilderwithEqualsForType(BiPredicate<? super T,? super T> equals, Class<T> type)Registers the givenBiPredicateto compare the fields with the given type.RecursiveComparisonConfiguration.BuilderwithErrorMessageForFields(String message, String... fields)Registers the giving message which would be shown when differences in the given fields while comparison occurred.RecursiveComparisonConfiguration.BuilderwithErrorMessageForType(String message, Class<?> type)Registers the giving message which would be shown when differences for the giving type while comparison occurred.RecursiveComparisonConfiguration.BuilderwithIgnoreAllActualEmptyOptionalFields(boolean ignoreAllActualEmptyOptionalFields)Sets whether actual empty optional fields are ignored in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)Sets whether actual null fields are ignored in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithIgnoreAllExpectedNullFields(boolean ignoreAllExpectedNullFields)Sets whether expected null fields are ignored in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithIgnoreAllOverriddenEquals(boolean ignoreAllOverriddenEquals)Force a recursive comparison on all fields (except java types) if true.RecursiveComparisonConfiguration.BuilderwithIgnoreCollectionOrder(boolean ignoreCollectionOrder)Sets whether to ignore collection order in the comparison.RecursiveComparisonConfiguration.BuilderwithIgnoredCollectionOrderInFields(String... fieldsToIgnoreCollectionOrder)Adds the given fields to the list fields from the object under test to ignore collection order in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithIgnoredCollectionOrderInFieldsMatchingRegexes(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.RecursiveComparisonConfiguration.BuilderwithIgnoredFields(String... fieldsToIgnore)Adds the given fields to the set of fields from the object under test to ignore in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithIgnoredFieldsMatchingRegexes(String... regexes)Allows to ignore in the recursive comparison the object under test fields matching the given regexes.RecursiveComparisonConfiguration.BuilderwithIgnoredFieldsOfTypes(Class<?>... types)Adds the given types to the list fields from the object under test types to ignore in the recursive comparison.RecursiveComparisonConfiguration.BuilderwithIgnoredOverriddenEqualsForFields(String... fields)Adds the given fields to the list of fields to force a recursive comparison on.RecursiveComparisonConfiguration.BuilderwithIgnoredOverriddenEqualsForFieldsMatchingRegexes(String... regexes)Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.RecursiveComparisonConfiguration.BuilderwithIgnoredOverriddenEqualsForTypes(Class<?>... types)Adds the given types to the list of types to force a recursive comparison on.RecursiveComparisonConfiguration.BuilderwithStrictTypeChecking(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).
-
-
-
Field Detail
-
strictTypeChecking
private boolean strictTypeChecking
-
ignoreAllActualNullFields
private boolean ignoreAllActualNullFields
-
ignoreAllActualEmptyOptionalFields
private boolean ignoreAllActualEmptyOptionalFields
-
ignoreAllExpectedNullFields
private boolean ignoreAllExpectedNullFields
-
ignoredFields
private String[] ignoredFields
-
comparedFields
private String[] comparedFields
-
ignoredFieldsMatchingRegexes
private String[] ignoredFieldsMatchingRegexes
-
ignoredTypes
private Class<?>[] ignoredTypes
-
ignoredOverriddenEqualsForTypes
private Class<?>[] ignoredOverriddenEqualsForTypes
-
ignoredOverriddenEqualsForFields
private String[] ignoredOverriddenEqualsForFields
-
ignoredOverriddenEqualsForFieldsMatchingRegexes
private String[] ignoredOverriddenEqualsForFieldsMatchingRegexes
-
ignoreAllOverriddenEquals
private boolean ignoreAllOverriddenEquals
-
ignoreCollectionOrder
private boolean ignoreCollectionOrder
-
ignoredCollectionOrderInFields
private String[] ignoredCollectionOrderInFields
-
ignoredCollectionOrderInFieldsMatchingRegexes
private String[] ignoredCollectionOrderInFieldsMatchingRegexes
-
typeComparators
private org.assertj.core.internal.TypeComparators typeComparators
-
fieldComparators
private FieldComparators fieldComparators
-
fieldMessages
private FieldMessages fieldMessages
-
typeMessages
private org.assertj.core.internal.TypeMessages typeMessages
-
-
Method Detail
-
withStrictTypeChecking
public RecursiveComparisonConfiguration.Builder 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). 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.
-
withIgnoredFields
public RecursiveComparisonConfiguration.Builder withIgnoredFields(String... fieldsToIgnore)
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.
-
withComparedFields
public RecursiveComparisonConfiguration.Builder withComparedFields(String... fieldsToCompare)
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.
-
withIgnoredFieldsMatchingRegexes
public RecursiveComparisonConfiguration.Builder withIgnoredFieldsMatchingRegexes(String... regexes)
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
public RecursiveComparisonConfiguration.Builder withIgnoredFieldsOfTypes(Class<?>... types)
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.
-
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 in the comparison.- Returns:
- this builder.
-
withComparatorForType
public <T> RecursiveComparisonConfiguration.Builder withComparatorForType(Comparator<? super T> comparator, 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
withComparatorForFields(Comparator, String...)or BiPredicate registered withwithEqualsForFields(BiPredicate, 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 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 givenBiPredicateto 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
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 BiPredicate for- Parameters:
equals- theBiPredicateto 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 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
withComparatorForType(Comparator, Class)or BiPredicate registered withwithEqualsForType(BiPredicate, Class).Note that registering a
Comparatorfor a given field will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert#withComparatorForFields(Comparator comparator, String...fields)for examples.- Parameters:
comparator- theComparatorto 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 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: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
BiPredicatefor a given field will override the previously registered BiPredicate/Comparator (if any).See
RecursiveComparisonAssert#withEqualsForFields(BiPredicate equals, String...fields)for examples.- Parameters:
equals- theBiPredicateto 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
-
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
Foohas aBarfield and both have anidfield, one can register a message for Foo and Bar'sidby 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
nullas 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
nullas 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
-
build
public RecursiveComparisonConfiguration build()
-
-