Class RecursiveComparisonConfiguration
- java.lang.Object
-
- org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration
-
public class RecursiveComparisonConfiguration extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private FieldComparatorsfieldComparatorsprivate booleanignoreAllActualNullFieldsprivate booleanignoreAllOverriddenEqualsprivate booleanignoreCollectionOrderprivate java.util.Set<FieldLocation>ignoredCollectionOrderInFieldsprivate java.util.List<java.util.regex.Pattern>ignoredCollectionOrderInFieldsMatchingRegexesprivate java.util.Set<FieldLocation>ignoredFieldsprivate java.util.List<java.util.regex.Pattern>ignoredFieldsRegexesprivate java.util.List<FieldLocation>ignoredOverriddenEqualsForFieldsprivate java.util.List<java.lang.Class<?>>ignoredOverriddenEqualsForTypesprivate java.util.List<java.util.regex.Pattern>ignoredOverriddenEqualsRegexesstatic java.lang.StringINDENT_LEVEL_2private booleanstrictTypeCheckingprivate TypeComparatorstypeComparators
-
Constructor Summary
Constructors Constructor Description RecursiveComparisonConfiguration()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.stream.Stream<java.util.Map.Entry<FieldLocation,java.util.Comparator<?>>>comparatorByFields()(package private) java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>>>comparatorByTypes()private static java.lang.StringconcatenatedPath(java.lang.String parentPath, java.lang.String name)private voiddescribeComparatorForFields(java.lang.StringBuilder description)private voiddescribeComparatorForTypes(java.lang.StringBuilder description)private voiddescribeIgnoreAllActualNullFields(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.StringdescribeIgnoredFields()private voiddescribeIgnoredFields(java.lang.StringBuilder description)private voiddescribeIgnoredFieldsRegexes(java.lang.StringBuilder description)private java.lang.StringdescribeIgnoredOverriddenEqualsForFields()private java.lang.StringdescribeIgnoredOverriddenEqualsForTypes(Representation representation)private voiddescribeIgnoredOverriddenEqualsMethods(java.lang.StringBuilder description, Representation representation)private voiddescribeOverriddenEqualsMethodsUsage(java.lang.StringBuilder description, Representation representation)private java.lang.StringdescribeRegexes(java.util.List<java.util.regex.Pattern> regexes)private voiddescribeRegisteredComparatorByTypes(java.lang.StringBuilder description)private voiddescribeRegisteredComparatorForFields(java.lang.StringBuilder description)private voiddescribeTypeCheckingStrictness(java.lang.StringBuilder description)private java.lang.StringformatRegisteredComparatorByType(java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>> next)private java.lang.StringformatRegisteredComparatorForField(java.util.Map.Entry<FieldLocation,java.util.Comparator<?>> comparatorForField)java.util.Comparator<?>getComparatorForField(java.lang.String fieldName)java.util.Comparator<?>getComparatorForType(java.lang.Class<?> fieldType)FieldComparatorsgetFieldComparators()(package private) booleangetIgnoreAllActualNullFields()(package private) booleangetIgnoreCollectionOrder()java.util.Set<FieldLocation>getIgnoredCollectionOrderInFields()Returns the list of the object under test fields 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.Set<FieldLocation>getIgnoredFields()Returns the list of the object under test fields to ignore in the recursive comparison.java.util.List<java.util.regex.Pattern>getIgnoredFieldsRegexes()java.util.List<FieldLocation>getIgnoredOverriddenEqualsForFields()java.util.List<java.lang.Class<?>>getIgnoredOverriddenEqualsForTypes()java.util.List<java.util.regex.Pattern>getIgnoredOverriddenEqualsRegexes()TypeComparatorsgetTypeComparators()booleanhasComparatorForField(java.lang.String fieldName)booleanhasComparatorForType(java.lang.Class<?> keyType)booleanhasCustomComparators()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 of the object under test fields 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.voidignoreFields(java.lang.String... fieldsToIgnore)Adds the given fields to the list of the object under test fields to ignore in the recursive comparison.voidignoreFieldsMatchingRegexes(java.lang.String... regexes)Allows to ignore in the recursive comparison the object under test fields matching the given regexes.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.private booleanisConfiguredToIgnoreSomeOverriddenEqualsMethods()booleanisInStrictTypeCheckingMode()private booleanmatchesAnIgnoredCollectionOrderInField(DualValue dualKey)private booleanmatchesAnIgnoredCollectionOrderInFieldRegex(DualValue dualKey)private booleanmatchesAnIgnoredField(java.lang.String fieldConcatenatedPath)private booleanmatchesAnIgnoredField(DualValue dualKey)private booleanmatchesAnIgnoredFieldRegex(java.lang.String fieldConcatenatedPath)private booleanmatchesAnIgnoredFieldRegex(DualValue dualKey)private booleanmatchesAnIgnoredNullField(DualValue dualKey)private booleanmatchesAnIgnoredOverriddenEqualsField(DualValue dualKey)private booleanmatchesAnIgnoredOverriddenEqualsRegex(java.lang.Class<?> clazz)private booleanmatchesAnIgnoredOverriddenEqualsType(java.lang.Class<?> clazz)java.lang.StringmultiLineDescription(Representation representation)voidregisterComparatorForField(java.util.Comparator<?> comparator, FieldLocation fieldLocation)Registers the givenComparatorto compare the fields with 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.voidsetIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)Sets whether actual null fields are ignored in the recursive comparison.(package private) booleanshouldIgnore(DualValue dualKey)(package private) booleanshouldIgnoreCollectionOrder(DualValue dualKey)(package private) booleanshouldIgnoreOverriddenEqualsOf(java.lang.Class<? extends java.lang.Object> clazz)(package private) booleanshouldIgnoreOverriddenEqualsOf(DualValue dualValue)(package private) java.util.function.Predicate<java.lang.String>shouldKeepField(java.lang.String parentConcatenatedPath)private booleanshouldKeepField(java.lang.String parentPath, java.lang.String fieldName)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).java.lang.StringtoString()
-
-
-
Field Detail
-
INDENT_LEVEL_2
public static final java.lang.String INDENT_LEVEL_2
- See Also:
- Constant Field Values
-
strictTypeChecking
private boolean strictTypeChecking
-
ignoreAllActualNullFields
private boolean ignoreAllActualNullFields
-
ignoredFields
private java.util.Set<FieldLocation> ignoredFields
-
ignoredFieldsRegexes
private java.util.List<java.util.regex.Pattern> ignoredFieldsRegexes
-
ignoredOverriddenEqualsForTypes
private java.util.List<java.lang.Class<?>> ignoredOverriddenEqualsForTypes
-
ignoredOverriddenEqualsForFields
private java.util.List<FieldLocation> ignoredOverriddenEqualsForFields
-
ignoredOverriddenEqualsRegexes
private java.util.List<java.util.regex.Pattern> ignoredOverriddenEqualsRegexes
-
ignoreAllOverriddenEquals
private boolean ignoreAllOverriddenEquals
-
ignoreCollectionOrder
private boolean ignoreCollectionOrder
-
ignoredCollectionOrderInFields
private java.util.Set<FieldLocation> ignoredCollectionOrderInFields
-
ignoredCollectionOrderInFieldsMatchingRegexes
private java.util.List<java.util.regex.Pattern> ignoredCollectionOrderInFieldsMatchingRegexes
-
typeComparators
private TypeComparators typeComparators
-
fieldComparators
private FieldComparators fieldComparators
-
-
Method Detail
-
hasComparatorForField
public boolean hasComparatorForField(java.lang.String fieldName)
-
getComparatorForField
public java.util.Comparator<?> getComparatorForField(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)
-
getTypeComparators
public TypeComparators getTypeComparators()
-
comparatorByTypes
java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>>> comparatorByTypes()
-
getIgnoreAllActualNullFields
boolean getIgnoreAllActualNullFields()
-
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 ingore actual null fields in the recursive comparison
-
ignoreFields
public void ignoreFields(java.lang.String... fieldsToIgnore)
Adds the given fields to the list of the object under test fields to ignore in the recursive comparison.See
RecursiveComparisonAssert#ignoringFields(String...)for examples.- Parameters:
fieldsToIgnore- the fields of the object under test to ignore in the comparison.
-
ignoreFieldsMatchingRegexes
public void ignoreFieldsMatchingRegexes(java.lang.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.
-
getIgnoredFields
public java.util.Set<FieldLocation> 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.
-
ignoreAllOverriddenEquals
public void ignoreAllOverriddenEquals()
Force a recursive comparison on all fields (except java types).See
RecursiveComparisonAssert.ignoringAllOverriddenEquals()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
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
public void ignoreCollectionOrderInFields(java.lang.String... fieldsToIgnoreCollectionOrder)
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
public java.util.Set<FieldLocation> 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
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 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 specified by this method have less precedence than comparators added with
registerComparatorForField(Comparator, FieldLocation).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.
-
registerComparatorForField
public void registerComparatorForField(java.util.Comparator<?> comparator, FieldLocation fieldLocation)Registers the givenComparatorto compare the fields with the given locations.The field locations must be specified from the root object, for example if
Foohas aBarfield which has anid, one can register to a comparator for Bar'sidby calling:registerComparatorForField(new FieldLocation("bar.id"), idComparator)Comparators specified by this method have precedence over comparators added with
registerComparatorForType(Comparator, Class).See
RecursiveComparisonAssert#withComparatorForFields(Comparator, String...)for examples.- Parameters:
comparator- theComparatorto use to compare the given fieldfieldLocation- the location from the root object of the field the comparator 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()
-
getIgnoredFieldsRegexes
public java.util.List<java.util.regex.Pattern> getIgnoredFieldsRegexes()
-
getIgnoredOverriddenEqualsForTypes
public java.util.List<java.lang.Class<?>> getIgnoredOverriddenEqualsForTypes()
-
getIgnoredOverriddenEqualsForFields
public java.util.List<FieldLocation> getIgnoredOverriddenEqualsForFields()
-
getIgnoredOverriddenEqualsRegexes
public java.util.List<java.util.regex.Pattern> getIgnoredOverriddenEqualsRegexes()
-
comparatorByFields
public java.util.stream.Stream<java.util.Map.Entry<FieldLocation,java.util.Comparator<?>>> comparatorByFields()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
multiLineDescription
public java.lang.String multiLineDescription(Representation representation)
-
shouldIgnore
boolean shouldIgnore(DualValue dualKey)
-
shouldKeepField
java.util.function.Predicate<java.lang.String> shouldKeepField(java.lang.String parentConcatenatedPath)
-
shouldKeepField
private boolean shouldKeepField(java.lang.String parentPath, java.lang.String fieldName)
-
concatenatedPath
private static java.lang.String concatenatedPath(java.lang.String parentPath, java.lang.String name)
-
shouldIgnoreOverriddenEqualsOf
boolean shouldIgnoreOverriddenEqualsOf(DualValue dualValue)
-
shouldIgnoreOverriddenEqualsOf
boolean shouldIgnoreOverriddenEqualsOf(java.lang.Class<? extends java.lang.Object> clazz)
-
shouldIgnoreCollectionOrder
boolean shouldIgnoreCollectionOrder(DualValue dualKey)
-
describeIgnoredFieldsRegexes
private void describeIgnoredFieldsRegexes(java.lang.StringBuilder description)
-
describeIgnoredFields
private void describeIgnoredFields(java.lang.StringBuilder description)
-
describeIgnoreAllActualNullFields
private void describeIgnoreAllActualNullFields(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)
-
matchesAnIgnoredOverriddenEqualsRegex
private boolean matchesAnIgnoredOverriddenEqualsRegex(java.lang.Class<?> clazz)
-
matchesAnIgnoredOverriddenEqualsType
private boolean matchesAnIgnoredOverriddenEqualsType(java.lang.Class<?> clazz)
-
matchesAnIgnoredOverriddenEqualsField
private boolean matchesAnIgnoredOverriddenEqualsField(DualValue dualKey)
-
matchesAnIgnoredNullField
private boolean matchesAnIgnoredNullField(DualValue dualKey)
-
matchesAnIgnoredFieldRegex
private boolean matchesAnIgnoredFieldRegex(java.lang.String fieldConcatenatedPath)
-
matchesAnIgnoredFieldRegex
private boolean matchesAnIgnoredFieldRegex(DualValue dualKey)
-
matchesAnIgnoredField
private boolean matchesAnIgnoredField(DualValue dualKey)
-
matchesAnIgnoredField
private boolean matchesAnIgnoredField(java.lang.String fieldConcatenatedPath)
-
matchesAnIgnoredCollectionOrderInField
private boolean matchesAnIgnoredCollectionOrderInField(DualValue dualKey)
-
matchesAnIgnoredCollectionOrderInFieldRegex
private boolean matchesAnIgnoredCollectionOrderInFieldRegex(DualValue dualKey)
-
describeIgnoredFields
private java.lang.String describeIgnoredFields()
-
describeIgnoredCollectionOrderInFields
private java.lang.String describeIgnoredCollectionOrderInFields()
-
describeRegexes
private java.lang.String describeRegexes(java.util.List<java.util.regex.Pattern> regexes)
-
isConfiguredToIgnoreSomeOverriddenEqualsMethods
private boolean isConfiguredToIgnoreSomeOverriddenEqualsMethods()
-
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)
-
formatRegisteredComparatorForField
private java.lang.String formatRegisteredComparatorForField(java.util.Map.Entry<FieldLocation,java.util.Comparator<?>> comparatorForField)
-
describeTypeCheckingStrictness
private void describeTypeCheckingStrictness(java.lang.StringBuilder description)
-
-