Class RecursiveComparisonConfiguration


  • public class RecursiveComparisonConfiguration
    extends java.lang.Object
    • Field Detail

      • strictTypeChecking

        private boolean strictTypeChecking
      • ignoreAllActualNullFields

        private boolean ignoreAllActualNullFields
      • ignoreAllActualEmptyOptionalFields

        private boolean ignoreAllActualEmptyOptionalFields
      • ignoreAllExpectedNullFields

        private boolean ignoreAllExpectedNullFields
      • ignoredFields

        private java.util.Set<FieldLocation> ignoredFields
      • ignoredFieldsRegexes

        private java.util.List<java.util.regex.Pattern> ignoredFieldsRegexes
      • ignoredTypes

        private java.util.Set<java.lang.Class<?>> ignoredTypes
      • 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
    • Constructor Detail

      • RecursiveComparisonConfiguration

        public RecursiveComparisonConfiguration()
    • Method Detail

      • hasComparatorForField

        public boolean hasComparatorForField​(java.lang.String fieldName)
      • getComparatorForField

        public java.util.Comparator<?> getComparatorForField​(java.lang.String fieldName)
      • hasComparatorForType

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

        public boolean hasCustomComparators()
      • getComparatorForType

        public java.util.Comparator<?> getComparatorForType​(java.lang.Class<?> fieldType)
      • comparatorByTypes

        java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,​java.util.Comparator<?>>> comparatorByTypes()
      • getIgnoreAllActualNullFields

        boolean getIgnoreAllActualNullFields()
      • 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​(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.
      • ignoreFieldsOfTypes

        public void ignoreFieldsOfTypes​(java.lang.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#ignoringFields(String...) for examples.

        Parameters:
        types - the types of the object under test to ignore in the comparison.
      • asWrapperIfPrimitiveType

        private static java.lang.Class<?> asWrapperIfPrimitiveType​(java.lang.Class<?> type)
      • 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.
      • getIgnoredTypes

        public java.util.Set<java.lang.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.
      • 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 given Comparator 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 - the Comparator to use to compare the given field
        type - the type to be compared with the given comparator.
      • registerComparatorForField

        public void registerComparatorForField​(java.util.Comparator<?> comparator,
                                               FieldLocation fieldLocation)
        Registers the given Comparator to compare the fields with the given locations.

        The field locations must be specified from the root object, for example if Foo has a Bar field which has an id, one can register to a comparator for Bar's id 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 - the Comparator to use to compare the given field
        fieldLocation - 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:
        toString in class java.lang.Object
      • multiLineDescription

        public java.lang.String multiLineDescription​(Representation representation)
      • shouldIgnore

        boolean shouldIgnore​(DualValue dualValue)
      • getNonIgnoredActualFieldNames

        java.util.Set<java.lang.String> getNonIgnoredActualFieldNames​(DualValue dualValue)
      • shouldIgnoreFieldButWithoutNeedingEvaluatingFieldName

        private boolean shouldIgnoreFieldButWithoutNeedingEvaluatingFieldName​(DualValue dualValue)
      • shouldIgnore

        private boolean shouldIgnore​(java.util.List<java.lang.String> parentConcatenatedPath,
                                     java.lang.String fieldName)
      • dualValueForField

        private static DualValue dualValueForField​(DualValue parentDualValue,
                                                   java.lang.String fieldName)
      • hasCustomComparator

        boolean hasCustomComparator​(DualValue dualValue)
      • shouldIgnoreOverriddenEqualsOf

        boolean shouldIgnoreOverriddenEqualsOf​(DualValue dualValue)
      • shouldIgnoreOverriddenEqualsOf

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

        boolean shouldIgnoreCollectionOrder​(DualValue dualValue)
      • describeIgnoredFieldsRegexes

        private void describeIgnoredFieldsRegexes​(java.lang.StringBuilder description)
      • describeIgnoredFields

        private void describeIgnoredFields​(java.lang.StringBuilder description)
      • describeIgnoredFieldsForTypes

        private void describeIgnoredFieldsForTypes​(java.lang.StringBuilder description)
      • describeIgnoreAllActualNullFields

        private void describeIgnoreAllActualNullFields​(java.lang.StringBuilder description)
      • describeIgnoreAllActualEmptyOptionalFields

        private void describeIgnoreAllActualEmptyOptionalFields​(java.lang.StringBuilder description)
      • describeIgnoreAllExpectedNullFields

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

        private boolean matchesAnIgnoredNullField​(DualValue dualValue)
      • matchesAnIgnoredEmptyOptionalField

        private boolean matchesAnIgnoredEmptyOptionalField​(DualValue dualValue)
      • matchesAnIgnoredFieldRegex

        private boolean matchesAnIgnoredFieldRegex​(java.lang.String fieldConcatenatedPath)
      • matchesAnIgnoredFieldType

        private boolean matchesAnIgnoredFieldType​(DualValue dualValue)
      • matchesAnIgnoredField

        private boolean matchesAnIgnoredField​(java.lang.String fieldConcatenatedPath)
      • matchesAnIgnoredCollectionOrderInField

        private boolean matchesAnIgnoredCollectionOrderInField​(DualValue dualValue)
      • matchesAnIgnoredCollectionOrderInFieldRegex

        private boolean matchesAnIgnoredCollectionOrderInFieldRegex​(DualValue dualValue)
      • describeIgnoredFields

        private java.lang.String describeIgnoredFields()
      • describeIgnoredTypes

        private java.lang.String describeIgnoredTypes()
      • 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)