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 FieldComparators
fieldComparators
private boolean
ignoreAllActualNullFields
private boolean
ignoreAllOverriddenEquals
private boolean
ignoreCollectionOrder
private Set<FieldLocation>
ignoredCollectionOrderInFields
private List<Pattern>
ignoredCollectionOrderInFieldsMatchingRegexes
private Set<FieldLocation>
ignoredFields
private List<Pattern>
ignoredFieldsRegexes
private List<FieldLocation>
ignoredOverriddenEqualsForFields
private List<Class<?>>
ignoredOverriddenEqualsForTypes
private List<Pattern>
ignoredOverriddenEqualsRegexes
static String
INDENT_LEVEL_2
private boolean
strictTypeChecking
private TypeComparators
typeComparators
-
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 String
concatenatedPath(String parentPath, String name)
private void
describeComparatorForFields(StringBuilder description)
private void
describeComparatorForTypes(StringBuilder description)
private void
describeIgnoreAllActualNullFields(StringBuilder description)
private void
describeIgnoreCollectionOrder(StringBuilder description)
private String
describeIgnoredCollectionOrderInFields()
private void
describeIgnoredCollectionOrderInFields(StringBuilder description)
private void
describeIgnoredCollectionOrderInFieldsMatchingRegexes(StringBuilder description)
private String
describeIgnoredFields()
private void
describeIgnoredFields(StringBuilder description)
private void
describeIgnoredFieldsRegexes(StringBuilder description)
private String
describeIgnoredOverriddenEqualsForFields()
private String
describeIgnoredOverriddenEqualsForTypes(Representation representation)
private void
describeIgnoredOverriddenEqualsMethods(StringBuilder description, Representation representation)
private void
describeOverriddenEqualsMethodsUsage(StringBuilder description, Representation representation)
private String
describeRegexes(List<Pattern> regexes)
private void
describeRegisteredComparatorByTypes(StringBuilder description)
private void
describeRegisteredComparatorForFields(StringBuilder description)
private void
describeTypeCheckingStrictness(StringBuilder description)
private String
formatRegisteredComparatorByType(Map.Entry<Class<?>,Comparator<?>> next)
private String
formatRegisteredComparatorForField(Map.Entry<FieldLocation,Comparator<?>> comparatorForField)
Comparator<?>
getComparatorForField(String fieldName)
Comparator<?>
getComparatorForType(Class<?> fieldType)
FieldComparators
getFieldComparators()
(package private) boolean
getIgnoreAllActualNullFields()
(package private) boolean
getIgnoreCollectionOrder()
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()
TypeComparators
getTypeComparators()
boolean
hasComparatorForField(String fieldName)
boolean
hasComparatorForType(Class<?> keyType)
boolean
hasCustomComparators()
void
ignoreAllOverriddenEquals()
Force a recursive comparison on all fields (except java types).void
ignoreCollectionOrder(boolean ignoreCollectionOrder)
Sets whether to ignore collection order in the comparison.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.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.void
ignoreFields(String... fieldsToIgnore)
Adds the given fields to the list of the object under test fields to ignore in the recursive comparison.void
ignoreFieldsMatchingRegexes(String... regexes)
Allows to ignore in the recursive comparison the object under test fields matching the given regexes.void
ignoreOverriddenEqualsForFields(String... fields)
Adds the given fields to the list of fields to force a recursive comparison on.void
ignoreOverriddenEqualsForFieldsMatchingRegexes(String... regexes)
Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.void
ignoreOverriddenEqualsForTypes(Class<?>... types)
Adds the given types to the list of types to force a recursive comparison on.private boolean
isConfiguredToIgnoreSomeOverriddenEqualsMethods()
boolean
isInStrictTypeCheckingMode()
private boolean
matchesAnIgnoredCollectionOrderInField(DualValue dualKey)
private boolean
matchesAnIgnoredCollectionOrderInFieldRegex(DualValue dualKey)
private boolean
matchesAnIgnoredField(String fieldConcatenatedPath)
private boolean
matchesAnIgnoredField(DualValue dualKey)
private boolean
matchesAnIgnoredFieldRegex(String fieldConcatenatedPath)
private boolean
matchesAnIgnoredFieldRegex(DualValue dualKey)
private boolean
matchesAnIgnoredNullField(DualValue dualKey)
private boolean
matchesAnIgnoredOverriddenEqualsField(DualValue dualKey)
private boolean
matchesAnIgnoredOverriddenEqualsRegex(Class<?> clazz)
private boolean
matchesAnIgnoredOverriddenEqualsType(Class<?> clazz)
String
multiLineDescription(Representation representation)
void
registerComparatorForField(Comparator<?> comparator, FieldLocation fieldLocation)
Registers the givenComparator
to compare the fields with the given locations.<T> void
registerComparatorForType(Comparator<? super T> comparator, Class<T> type)
Registers the givenComparator
to compare the fields with the given type.void
setIgnoreAllActualNullFields(boolean ignoreAllActualNullFields)
Sets whether actual null fields are ignored in the recursive comparison.(package private) boolean
shouldIgnore(DualValue dualKey)
(package private) boolean
shouldIgnoreCollectionOrder(DualValue dualKey)
(package private) boolean
shouldIgnoreOverriddenEqualsOf(Class<? extends Object> clazz)
(package private) boolean
shouldIgnoreOverriddenEqualsOf(DualValue dualValue)
(package private) Predicate<String>
shouldKeepField(String parentConcatenatedPath)
private boolean
shouldKeepField(String parentPath, String fieldName)
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).String
toString()
-
-
-
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 ignore 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 givenComparator
to 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
- theComparator
to 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 givenComparator
to compare the fields with the given locations.The field locations must be specified from the root object, for example if
Foo
has aBar
field which has anid
, one can register to a comparator for Bar'sid
by 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
- theComparator
to 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)
-
-