Class RecursiveComparisonConfiguration
- java.lang.Object
-
- org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration
-
public class RecursiveComparisonConfiguration extends Object
-
-
Field Summary
Fields Modifier and Type Field Description private FieldComparatorsfieldComparatorsprivate booleanignoreAllActualNullFieldsprivate booleanignoreAllOverriddenEqualsprivate booleanignoreCollectionOrderprivate Set<FieldLocation>ignoredCollectionOrderInFieldsprivate List<Pattern>ignoredCollectionOrderInFieldsMatchingRegexesprivate Set<FieldLocation>ignoredFieldsprivate List<Pattern>ignoredFieldsRegexesprivate List<FieldLocation>ignoredOverriddenEqualsForFieldsprivate List<Class<?>>ignoredOverriddenEqualsForTypesprivate List<Pattern>ignoredOverriddenEqualsRegexesstatic 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 Stream<Map.Entry<FieldLocation,Comparator<?>>>comparatorByFields()(package private) Stream<Map.Entry<Class<?>,Comparator<?>>>comparatorByTypes()private static StringconcatenatedPath(String parentPath, String name)private voiddescribeComparatorForFields(StringBuilder description)private voiddescribeComparatorForTypes(StringBuilder description)private voiddescribeIgnoreAllActualNullFields(StringBuilder description)private voiddescribeIgnoreCollectionOrder(StringBuilder description)private StringdescribeIgnoredCollectionOrderInFields()private voiddescribeIgnoredCollectionOrderInFields(StringBuilder description)private voiddescribeIgnoredCollectionOrderInFieldsMatchingRegexes(StringBuilder description)private StringdescribeIgnoredFields()private voiddescribeIgnoredFields(StringBuilder description)private voiddescribeIgnoredFieldsRegexes(StringBuilder description)private StringdescribeIgnoredOverriddenEqualsForFields()private StringdescribeIgnoredOverriddenEqualsForTypes(Representation representation)private voiddescribeIgnoredOverriddenEqualsMethods(StringBuilder description, Representation representation)private voiddescribeOverriddenEqualsMethodsUsage(StringBuilder description, Representation representation)private StringdescribeRegexes(List<Pattern> regexes)private voiddescribeRegisteredComparatorByTypes(StringBuilder description)private voiddescribeRegisteredComparatorForFields(StringBuilder description)private voiddescribeTypeCheckingStrictness(StringBuilder description)private StringformatRegisteredComparatorByType(Map.Entry<Class<?>,Comparator<?>> next)private StringformatRegisteredComparatorForField(Map.Entry<FieldLocation,Comparator<?>> comparatorForField)Comparator<?>getComparatorForField(String fieldName)Comparator<?>getComparatorForType(Class<?> fieldType)FieldComparatorsgetFieldComparators()(package private) booleangetIgnoreAllActualNullFields()(package private) booleangetIgnoreCollectionOrder()Set<FieldLocation>getIgnoredCollectionOrderInFields()Returns the list of the object under test fields to ignore collection order in the recursive comparison.List<Pattern>getIgnoredCollectionOrderInFieldsMatchingRegexes()Returns the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.Set<FieldLocation>getIgnoredFields()Returns the list of the object under test fields to ignore in the recursive comparison.List<Pattern>getIgnoredFieldsRegexes()List<FieldLocation>getIgnoredOverriddenEqualsForFields()List<Class<?>>getIgnoredOverriddenEqualsForTypes()List<Pattern>getIgnoredOverriddenEqualsRegexes()TypeComparatorsgetTypeComparators()booleanhasComparatorForField(String fieldName)booleanhasComparatorForType(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(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.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 booleanisConfiguredToIgnoreSomeOverriddenEqualsMethods()booleanisInStrictTypeCheckingMode()private booleanmatchesAnIgnoredCollectionOrderInField(DualValue dualKey)private booleanmatchesAnIgnoredCollectionOrderInFieldRegex(DualValue dualKey)private booleanmatchesAnIgnoredField(String fieldConcatenatedPath)private booleanmatchesAnIgnoredField(DualValue dualKey)private booleanmatchesAnIgnoredFieldRegex(String fieldConcatenatedPath)private booleanmatchesAnIgnoredFieldRegex(DualValue dualKey)private booleanmatchesAnIgnoredNullField(DualValue dualKey)private booleanmatchesAnIgnoredOverriddenEqualsField(DualValue dualKey)private booleanmatchesAnIgnoredOverriddenEqualsRegex(Class<?> clazz)private booleanmatchesAnIgnoredOverriddenEqualsType(Class<?> clazz)StringmultiLineDescription(Representation representation)voidregisterComparatorForField(Comparator<?> comparator, FieldLocation fieldLocation)Registers the givenComparatorto compare the fields with the given locations.<T> voidregisterComparatorForType(Comparator<? super T> comparator, 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(Class<? extends Object> clazz)(package private) booleanshouldIgnoreOverriddenEqualsOf(DualValue dualValue)(package private) Predicate<String>shouldKeepField(String parentConcatenatedPath)private booleanshouldKeepField(String parentPath, 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).StringtoString()
-
-
-
Field Detail
-
INDENT_LEVEL_2
public static final String INDENT_LEVEL_2
- See Also:
- Constant Field Values
-
strictTypeChecking
private boolean strictTypeChecking
-
ignoreAllActualNullFields
private boolean ignoreAllActualNullFields
-
ignoredFields
private Set<FieldLocation> ignoredFields
-
ignoredOverriddenEqualsForFields
private List<FieldLocation> ignoredOverriddenEqualsForFields
-
ignoreAllOverriddenEquals
private boolean ignoreAllOverriddenEquals
-
ignoreCollectionOrder
private boolean ignoreCollectionOrder
-
ignoredCollectionOrderInFields
private Set<FieldLocation> ignoredCollectionOrderInFields
-
ignoredCollectionOrderInFieldsMatchingRegexes
private List<Pattern> ignoredCollectionOrderInFieldsMatchingRegexes
-
typeComparators
private TypeComparators typeComparators
-
fieldComparators
private FieldComparators fieldComparators
-
-
Method Detail
-
hasComparatorForField
public boolean hasComparatorForField(String fieldName)
-
getComparatorForField
public Comparator<?> getComparatorForField(String fieldName)
-
getFieldComparators
public FieldComparators getFieldComparators()
-
hasComparatorForType
public boolean hasComparatorForType(Class<?> keyType)
-
hasCustomComparators
public boolean hasCustomComparators()
-
getComparatorForType
public Comparator<?> getComparatorForType(Class<?> fieldType)
-
getTypeComparators
public TypeComparators getTypeComparators()
-
comparatorByTypes
Stream<Map.Entry<Class<?>,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(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(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 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(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(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(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(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 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(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 List<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(Comparator<? super T> comparator, 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(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()
-
getIgnoredOverriddenEqualsForFields
public List<FieldLocation> getIgnoredOverriddenEqualsForFields()
-
comparatorByFields
public Stream<Map.Entry<FieldLocation,Comparator<?>>> comparatorByFields()
-
multiLineDescription
public String multiLineDescription(Representation representation)
-
shouldIgnore
boolean shouldIgnore(DualValue dualKey)
-
shouldIgnoreOverriddenEqualsOf
boolean shouldIgnoreOverriddenEqualsOf(DualValue dualValue)
-
shouldIgnoreOverriddenEqualsOf
boolean shouldIgnoreOverriddenEqualsOf(Class<? extends Object> clazz)
-
shouldIgnoreCollectionOrder
boolean shouldIgnoreCollectionOrder(DualValue dualKey)
-
describeIgnoredFieldsRegexes
private void describeIgnoredFieldsRegexes(StringBuilder description)
-
describeIgnoredFields
private void describeIgnoredFields(StringBuilder description)
-
describeIgnoreAllActualNullFields
private void describeIgnoreAllActualNullFields(StringBuilder description)
-
describeOverriddenEqualsMethodsUsage
private void describeOverriddenEqualsMethodsUsage(StringBuilder description, Representation representation)
-
describeIgnoredOverriddenEqualsMethods
private void describeIgnoredOverriddenEqualsMethods(StringBuilder description, Representation representation)
-
describeIgnoredOverriddenEqualsForTypes
private String describeIgnoredOverriddenEqualsForTypes(Representation representation)
-
describeIgnoredOverriddenEqualsForFields
private String describeIgnoredOverriddenEqualsForFields()
-
describeIgnoreCollectionOrder
private void describeIgnoreCollectionOrder(StringBuilder description)
-
describeIgnoredCollectionOrderInFields
private void describeIgnoredCollectionOrderInFields(StringBuilder description)
-
describeIgnoredCollectionOrderInFieldsMatchingRegexes
private void describeIgnoredCollectionOrderInFieldsMatchingRegexes(StringBuilder description)
-
matchesAnIgnoredOverriddenEqualsRegex
private boolean matchesAnIgnoredOverriddenEqualsRegex(Class<?> clazz)
-
matchesAnIgnoredOverriddenEqualsType
private boolean matchesAnIgnoredOverriddenEqualsType(Class<?> clazz)
-
matchesAnIgnoredOverriddenEqualsField
private boolean matchesAnIgnoredOverriddenEqualsField(DualValue dualKey)
-
matchesAnIgnoredNullField
private boolean matchesAnIgnoredNullField(DualValue dualKey)
-
matchesAnIgnoredFieldRegex
private boolean matchesAnIgnoredFieldRegex(String fieldConcatenatedPath)
-
matchesAnIgnoredFieldRegex
private boolean matchesAnIgnoredFieldRegex(DualValue dualKey)
-
matchesAnIgnoredField
private boolean matchesAnIgnoredField(DualValue dualKey)
-
matchesAnIgnoredField
private boolean matchesAnIgnoredField(String fieldConcatenatedPath)
-
matchesAnIgnoredCollectionOrderInField
private boolean matchesAnIgnoredCollectionOrderInField(DualValue dualKey)
-
matchesAnIgnoredCollectionOrderInFieldRegex
private boolean matchesAnIgnoredCollectionOrderInFieldRegex(DualValue dualKey)
-
describeIgnoredFields
private String describeIgnoredFields()
-
describeIgnoredCollectionOrderInFields
private String describeIgnoredCollectionOrderInFields()
-
isConfiguredToIgnoreSomeOverriddenEqualsMethods
private boolean isConfiguredToIgnoreSomeOverriddenEqualsMethods()
-
describeRegisteredComparatorByTypes
private void describeRegisteredComparatorByTypes(StringBuilder description)
-
describeComparatorForTypes
private void describeComparatorForTypes(StringBuilder description)
-
formatRegisteredComparatorByType
private String formatRegisteredComparatorByType(Map.Entry<Class<?>,Comparator<?>> next)
-
describeRegisteredComparatorForFields
private void describeRegisteredComparatorForFields(StringBuilder description)
-
describeComparatorForFields
private void describeComparatorForFields(StringBuilder description)
-
formatRegisteredComparatorForField
private String formatRegisteredComparatorForField(Map.Entry<FieldLocation,Comparator<?>> comparatorForField)
-
describeTypeCheckingStrictness
private void describeTypeCheckingStrictness(StringBuilder description)
-
-