Class AbstractRecursiveOperationConfiguration
- java.lang.Object
-
- org.assertj.core.api.recursive.AbstractRecursiveOperationConfiguration
-
- Direct Known Subclasses:
RecursiveAssertionConfiguration,RecursiveComparisonConfiguration
public abstract class AbstractRecursiveOperationConfiguration extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractRecursiveOperationConfiguration.AbstractBuilder<BUILDER_TYPE extends AbstractRecursiveOperationConfiguration.AbstractBuilder<BUILDER_TYPE>>
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringDEFAULT_DELIMITERprivate java.util.Set<java.lang.String>ignoredFieldsprivate java.util.List<java.util.regex.Pattern>ignoredFieldsRegexesprivate java.util.Set<java.lang.Class<?>>ignoredTypesprivate java.util.List<java.util.regex.Pattern>ignoredTypesRegexes
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRecursiveOperationConfiguration()protectedAbstractRecursiveOperationConfiguration(AbstractRecursiveOperationConfiguration.AbstractBuilder<?> builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.lang.Class<?>asWrapperIfPrimitiveType(java.lang.Class<?> type)private java.lang.StringdescribeIgnoredFields()protected voiddescribeIgnoredFields(java.lang.StringBuilder description)protected voiddescribeIgnoredFieldsRegexes(java.lang.StringBuilder description)protected java.lang.StringdescribeIgnoredTypes()protected java.lang.StringdescribeRegexes(java.util.List<java.util.regex.Pattern> regexes)java.util.Set<java.lang.String>getIgnoredFields()Returns the set of fields from the object under test to ignore in the recursive comparison.java.util.List<java.util.regex.Pattern>getIgnoredFieldsRegexes()java.util.Set<java.lang.Class<?>>getIgnoredTypes()Returns the set of fields from the object under test types to ignore in the recursive comparison.java.util.List<java.util.regex.Pattern>getIgnoredTypesRegexes()Returns the regexes that will be used to ignore fields with types matching these regexes in the recursive comparison.voidignoreFields(java.lang.String... fieldsToIgnore)Adds the given fields to the set of fields from the object under test to ignore in the recursive comparison.voidignoreFieldsMatchingRegexes(java.lang.String... regexes)Allows to ignore in the recursive comparison the object under test fields matching the given regexes.voidignoreFieldsOfTypes(java.lang.Class<?>... types)Makes the recursive assertion to ignore the object under test fields of the given types.voidignoreFieldsOfTypesMatchingRegexes(java.lang.String... regexes)Makes the recursive comparison to ignore the fields of the object under test having types matching one of the given regexes.protected static java.lang.Stringjoin(java.util.Collection<java.lang.String> typesDescription)booleanmatchesAnIgnoredField(FieldLocation fieldLocation)booleanmatchesAnIgnoredFieldRegex(FieldLocation fieldLocation)private static java.util.List<java.util.regex.Pattern>toPatterns(java.lang.String[] regexes)
-
-
-
Field Detail
-
DEFAULT_DELIMITER
protected static final java.lang.String DEFAULT_DELIMITER
- See Also:
- Constant Field Values
-
ignoredFields
private final java.util.Set<java.lang.String> ignoredFields
-
ignoredFieldsRegexes
private final java.util.List<java.util.regex.Pattern> ignoredFieldsRegexes
-
ignoredTypes
private final java.util.Set<java.lang.Class<?>> ignoredTypes
-
ignoredTypesRegexes
private final java.util.List<java.util.regex.Pattern> ignoredTypesRegexes
-
-
Constructor Detail
-
AbstractRecursiveOperationConfiguration
protected AbstractRecursiveOperationConfiguration(AbstractRecursiveOperationConfiguration.AbstractBuilder<?> builder)
-
AbstractRecursiveOperationConfiguration
protected AbstractRecursiveOperationConfiguration()
-
-
Method Detail
-
ignoreFields
public void ignoreFields(java.lang.String... fieldsToIgnore)
Adds the given fields to the set of fields from the object under test to ignore in the recursive comparison.The fields 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.
-
getIgnoredFields
public java.util.Set<java.lang.String> getIgnoredFields()
Returns the set of fields from the object under test to ignore in the recursive comparison.- Returns:
- the set of fields from the object under test to ignore in the recursive 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.
-
getIgnoredFieldsRegexes
public java.util.List<java.util.regex.Pattern> getIgnoredFieldsRegexes()
-
ignoreFieldsOfTypes
public void ignoreFieldsOfTypes(java.lang.Class<?>... types)
Makes the recursive assertion to ignore the object under test fields of the given types. The fields are ignored if their types exactly match one of the ignored types, for example if a field is a subtype of an ignored type it is not ignored.If some object under test fields are null it is not possible to evaluate their types and thus these fields are not ignored.
Example: see
RecursiveComparisonAssert.ignoringFieldsOfTypes(Class[]).- Parameters:
types- the types of the object under test to ignore in the comparison.
-
ignoreFieldsOfTypesMatchingRegexes
public void ignoreFieldsOfTypesMatchingRegexes(java.lang.String... regexes)
Makes the recursive comparison to ignore the fields of the object under test having types matching one of the given regexes. The fields are ignored if their types exactly match one of the regexes, if a field is a subtype of a matched type it is not ignored.One use case of this method is to ignore types that can't be introspected.
If
strictTypeCheckingmode is enabled and a field of the object under test is null, the recursive comparison evaluates the corresponding expected field's type (if not null), if it is disabled then the field is evaluated as usual (i.e. it is not ignored).Warning: primitive types are not directly supported because under the hood they are converted to their corresponding wrapping types, for example
inttojava.lang.Integer. The preferred way to ignore primitive types is to useignoreFieldsOfTypes(Class[]). Another way is to ignore the wrapping type, for example ignoringjava.lang.Integerignores bothjava.lang.Integerandintfields.Example: see
RecursiveComparisonAssert.ignoringFieldsOfTypesMatchingRegexes(String...).- Parameters:
regexes- regexes specifying the types to ignore.
-
asWrapperIfPrimitiveType
protected static java.lang.Class<?> asWrapperIfPrimitiveType(java.lang.Class<?> type)
-
getIgnoredTypes
public java.util.Set<java.lang.Class<?>> getIgnoredTypes()
Returns the set of fields from the object under test types to ignore in the recursive comparison.- Returns:
- the set of fields from the object under test types to ignore in the recursive comparison.
-
getIgnoredTypesRegexes
public java.util.List<java.util.regex.Pattern> getIgnoredTypesRegexes()
Returns the regexes that will be used to ignore fields with types matching these regexes in the recursive comparison.- Returns:
- the regexes that will be used to ignore fields with types matching these regexes in the recursive comparison.
-
describeIgnoredFields
protected void describeIgnoredFields(java.lang.StringBuilder description)
-
describeIgnoredFieldsRegexes
protected void describeIgnoredFieldsRegexes(java.lang.StringBuilder description)
-
describeIgnoredTypes
protected java.lang.String describeIgnoredTypes()
-
describeRegexes
protected java.lang.String describeRegexes(java.util.List<java.util.regex.Pattern> regexes)
-
join
protected static java.lang.String join(java.util.Collection<java.lang.String> typesDescription)
-
matchesAnIgnoredFieldRegex
public boolean matchesAnIgnoredFieldRegex(FieldLocation fieldLocation)
-
matchesAnIgnoredField
public boolean matchesAnIgnoredField(FieldLocation fieldLocation)
-
describeIgnoredFields
private java.lang.String describeIgnoredFields()
-
toPatterns
private static java.util.List<java.util.regex.Pattern> toPatterns(java.lang.String[] regexes)
-
-