Class RecursiveComparisonConfiguration


  • public class RecursiveComparisonConfiguration
    extends Object
    • Field Detail

      • strictTypeChecking

        private boolean strictTypeChecking
      • ignoreAllActualNullFields

        private boolean ignoreAllActualNullFields
      • ignoreAllActualEmptyOptionalFields

        private boolean ignoreAllActualEmptyOptionalFields
      • ignoreAllExpectedNullFields

        private boolean ignoreAllExpectedNullFields
      • ignoredFields

        private Set<String> ignoredFields
      • ignoredFieldsRegexes

        private List<Pattern> ignoredFieldsRegexes
      • ignoredTypes

        private Set<Class<?>> ignoredTypes
      • ignoredOverriddenEqualsForTypes

        private List<Class<?>> ignoredOverriddenEqualsForTypes
      • ignoredOverriddenEqualsForFields

        private List<String> ignoredOverriddenEqualsForFields
      • ignoredOverriddenEqualsForFieldsMatchingRegexes

        private List<Pattern> ignoredOverriddenEqualsForFieldsMatchingRegexes
      • ignoreAllOverriddenEquals

        private boolean ignoreAllOverriddenEquals
      • ignoreCollectionOrder

        private boolean ignoreCollectionOrder
      • ignoredCollectionOrderInFields

        private Set<String> ignoredCollectionOrderInFields
      • ignoredCollectionOrderInFieldsMatchingRegexes

        private List<Pattern> ignoredCollectionOrderInFieldsMatchingRegexes
    • Constructor Detail

      • RecursiveComparisonConfiguration

        public RecursiveComparisonConfiguration()
    • Method Detail

      • hasComparatorForField

        public boolean hasComparatorForField​(String fieldName)
      • getComparatorForField

        public Comparator<?> getComparatorForField​(String fieldName)
      • hasComparatorForType

        public boolean hasComparatorForType​(Class<?> keyType)
      • hasCustomComparators

        public boolean hasCustomComparators()
      • getComparatorForType

        public Comparator<?> getComparatorForType​(Class<?> fieldType)
      • getIgnoreAllActualNullFields

        boolean getIgnoreAllActualNullFields()
      • getIgnoreAllExpectedNullFields

        boolean getIgnoreAllExpectedNullFields()
      • getIgnoreAllOverriddenEquals

        boolean getIgnoreAllOverriddenEquals()
      • setIgnoreAllActualEmptyOptionalFields

        public void setIgnoreAllActualEmptyOptionalFields​(boolean ignoringAllActualEmptyOptionalFields)
        Sets whether actual empty optional fields are ignored in the recursive comparison.

        See RecursiveComparisonAssert.ignoringActualNullFields() for code examples.

        Parameters:
        ignoringAllActualEmptyOptionalFields - whether to ignore actual empty optional fields in the recursive comparison
      • getIgnoreAllActualEmptyOptionalFields

        boolean getIgnoreAllActualEmptyOptionalFields()
      • 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
      • setIgnoreAllExpectedNullFields

        public void setIgnoreAllExpectedNullFields​(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
      • 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.

        The field are ignored by name, not by value.

        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.
      • ignoreFieldsOfTypes

        public void ignoreFieldsOfTypes​(Class<?>... types)
        Adds the given types to the list of the object under test fields 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.
      • asWrapperIfPrimitiveType

        private static Class<?> asWrapperIfPrimitiveType​(Class<?> type)
      • getIgnoredFields

        public Set<String> 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.
      • getIgnoredTypes

        public Set<Class<?>> getIgnoredTypes()
        Returns the set of the object under test fields types to ignore in the recursive comparison.
        Returns:
        the set of the object under test fields types to ignore in the recursive comparison.
      • 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<String> 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.
      • registerComparatorForFields

        public void registerComparatorForFields​(Comparator<?> comparator,
                                                String... fieldLocations)
        Registers the given Comparator to compare the fields at the given locations.

        The fields must be specified from the root object, for example if Foo has a Bar field and both have an id field, one can register a comparator for Foo and Bar's id by calling:

         registerComparatorForFields(idComparator, "foo.id", "foo.bar.id")

        Comparators registered with this method have precedence over comparators registered with registerComparatorForType(Comparator, Class).

        Note that registering a Comparator for a given field will override the previously registered BiPredicate/Comparator (if any).

        See RecursiveComparisonAssert#withComparatorForFields(Comparator, String...) for examples.

        Parameters:
        comparator - the Comparator to use to compare the given field
        fieldLocations - the locations from the root object of the fields the comparator should be used for
        Throws:
        NullPointerException - if the given comparator is null.
      • registerEqualsForFields

        public void registerEqualsForFields​(BiPredicate<?,​?> equals,
                                            String... fieldLocations)
        Registers the given BiPredicate to compare the fields at the given locations.

        The fields must be specified from the root object, for example if Foo has a Bar field and both have an id field, one can register a BiPredicate for Foo and Bar's id by calling:

         registerEqualsForFields(idBiPredicate, "foo.id", "foo.bar.id")

        BiPredicates registered with this method have precedence over the ones registered with registerEqualsForType(BiPredicate, Class) or the comparators registered with registerComparatorForType(Comparator, Class).

        Note that registering a BiPredicate for a given field will override the previously registered BiPredicate/Comparator (if any).

        See RecursiveComparisonAssert#withEqualsForFields(BiPredicate, String...) for examples.

        Parameters:
        equals - the equals implementation to compare the given fields.
        fieldLocations - the locations from the root object of the fields the comparator should be used for
        Throws:
        NullPointerException - if the given BiPredicate is null.
        Since:
        3.17.0
      • 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 List<Pattern> getIgnoredFieldsRegexes()
      • getIgnoredOverriddenEqualsForTypes

        public List<Class<?>> getIgnoredOverriddenEqualsForTypes()
      • getIgnoredOverriddenEqualsForFields

        public List<String> getIgnoredOverriddenEqualsForFields()
      • getIgnoredOverriddenEqualsForFieldsMatchingRegexes

        public List<Pattern> getIgnoredOverriddenEqualsForFieldsMatchingRegexes()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • shouldIgnore

        boolean shouldIgnore​(DualValue dualValue)
      • getNonIgnoredActualFieldNames

        Set<String> getNonIgnoredActualFieldNames​(DualValue dualValue)
      • shouldIgnoreFieldBasedOnFieldValue

        private boolean shouldIgnoreFieldBasedOnFieldValue​(DualValue dualValue)
      • shouldIgnoreFieldBasedOnFieldLocation

        private boolean shouldIgnoreFieldBasedOnFieldLocation​(FieldLocation fieldLocation)
      • hasCustomComparator

        boolean hasCustomComparator​(DualValue dualValue)
      • shouldIgnoreOverriddenEqualsOf

        boolean shouldIgnoreOverriddenEqualsOf​(DualValue dualValue)
      • shouldIgnoreOverriddenEqualsOf

        boolean shouldIgnoreOverriddenEqualsOf​(Class<? extends Object> clazz)
      • shouldIgnoreCollectionOrder

        boolean shouldIgnoreCollectionOrder​(FieldLocation fieldLocation)
      • describeIgnoredFieldsRegexes

        private void describeIgnoredFieldsRegexes​(StringBuilder description)
      • describeIgnoredFields

        private void describeIgnoredFields​(StringBuilder description)
      • describeIgnoredFieldsForTypes

        private void describeIgnoredFieldsForTypes​(StringBuilder description)
      • describeIgnoreAllActualNullFields

        private void describeIgnoreAllActualNullFields​(StringBuilder description)
      • describeIgnoreAllActualEmptyOptionalFields

        private void describeIgnoreAllActualEmptyOptionalFields​(StringBuilder description)
      • describeIgnoreAllExpectedNullFields

        private void describeIgnoreAllExpectedNullFields​(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​(FieldLocation fieldLocation)
      • matchesAnIgnoredNullField

        private boolean matchesAnIgnoredNullField​(DualValue dualValue)
      • matchesAnIgnoredEmptyOptionalField

        private boolean matchesAnIgnoredEmptyOptionalField​(DualValue dualValue)
      • matchesAnIgnoredFieldRegex

        private boolean matchesAnIgnoredFieldRegex​(FieldLocation fieldLocation)
      • matchesAnIgnoredFieldType

        private boolean matchesAnIgnoredFieldType​(DualValue dualValue)
      • matchesAnIgnoredField

        private boolean matchesAnIgnoredField​(FieldLocation fieldLocation)
      • matchesAnIgnoredCollectionOrderInField

        private boolean matchesAnIgnoredCollectionOrderInField​(FieldLocation fieldLocation)
      • matchesAnIgnoredCollectionOrderInFieldRegex

        private boolean matchesAnIgnoredCollectionOrderInFieldRegex​(FieldLocation fieldLocation)
      • describeIgnoredFields

        private String describeIgnoredFields()
      • describeIgnoredTypes

        private String describeIgnoredTypes()
      • describeIgnoredCollectionOrderInFields

        private String describeIgnoredCollectionOrderInFields()
      • isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods

        private boolean isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods()
      • describeRegisteredComparatorByTypes

        private void describeRegisteredComparatorByTypes​(StringBuilder description)
      • describeComparatorForTypes

        private void describeComparatorForTypes​(StringBuilder description)
      • describeRegisteredComparatorForFields

        private void describeRegisteredComparatorForFields​(StringBuilder description)
      • describeComparatorForFields

        private void describeComparatorForFields​(StringBuilder description)
      • describeTypeCheckingStrictness

        private void describeTypeCheckingStrictness​(StringBuilder description)