Class RecursiveComparisonConfiguration


  • public class RecursiveComparisonConfiguration
    extends Object
    • Field Detail

      • strictTypeChecking

        private boolean strictTypeChecking
      • ignoreAllActualNullFields

        private boolean ignoreAllActualNullFields
      • ignoredFieldsRegexes

        private List<Pattern> ignoredFieldsRegexes
      • ignoredOverriddenEqualsForTypes

        private List<Class<?>> ignoredOverriddenEqualsForTypes
      • ignoredOverriddenEqualsForFields

        private List<FieldLocation> ignoredOverriddenEqualsForFields
      • ignoredOverriddenEqualsRegexes

        private List<Pattern> ignoredOverriddenEqualsRegexes
      • ignoreAllOverriddenEquals

        private boolean ignoreAllOverriddenEquals
      • ignoreCollectionOrder

        private boolean ignoreCollectionOrder
      • ignoredCollectionOrderInFields

        private Set<FieldLocation> 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()
      • 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.
      • 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.
      • registerComparatorForField

        public void registerComparatorForField​(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 List<Pattern> getIgnoredFieldsRegexes()
      • getIgnoredOverriddenEqualsForTypes

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

        public List<FieldLocation> getIgnoredOverriddenEqualsForFields()
      • getIgnoredOverriddenEqualsRegexes

        public List<Pattern> getIgnoredOverriddenEqualsRegexes()
      • shouldIgnore

        boolean shouldIgnore​(DualValue dualKey)
      • shouldKeepField

        private boolean shouldKeepField​(String parentPath,
                                        String fieldName)
      • concatenatedPath

        private static String concatenatedPath​(String parentPath,
                                               String name)
      • 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)
      • describeRegisteredComparatorForFields

        private void describeRegisteredComparatorForFields​(StringBuilder description)
      • describeComparatorForFields

        private void describeComparatorForFields​(StringBuilder description)
      • describeTypeCheckingStrictness

        private void describeTypeCheckingStrictness​(StringBuilder description)