An assertion that supports asserting a Predicate over all the fields of an object graph. Cycle avoidance is used,
so a graph that has cyclic references is essentially reduced to a tree by this class (the actual object graph is not changed
of course, it is treated as an immutable value).
| Modifier and Type | Field and Description |
|---|---|
| private final RecursiveAssertionConfiguration | |
| private final RecursiveAssertionDriver |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public RecursiveAssertionAssert | Returns: this assertions objectThe predicate that is recursively applied to all the fields in the object tree of which actual is the root. predicate)Asserts that the given predicate is met for all fields of the object under test recursively (but not the object itself). |
| public RecursiveAssertionAssert | Returns: this assertions objectAsserts that none of the fields of the object under test graph (i.e. recursively getting the fields) are null (but not the object itself). |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.Makes the recursive assertion to ignore all null fields. |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.the fields to ignore in the object under test. fieldsToIgnore)Makes the recursive assertion to ignore the specified fields in the object under test. |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.regexes used to ignore fields in the assertion. regexes)Makes the recursive assertion to ignore the fields matching the specified regexes in the object under test. |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.the types we want to ignore in the object under test fields. typesToIgnore)Makes the recursive assertion to ignore the object under test fields of the given types. |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.Make the recursive assertion not to run the |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.Makes the recursive assertion to use the specified |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.the introspectionStrategy)RecursiveAssertionIntrospectionStrategy to useDefines how objects are introspected in the recursive assertion. |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.Makes the recursive assertion to use the specified |
| public RecursiveAssertionAssert | Returns: thisRecursiveAssertionAssert to chain other methods.Makes the recursive assertion to use the specified |
| recursiveAssertionConfiguration | back to summary |
|---|---|
| private final RecursiveAssertionConfiguration recursiveAssertionConfiguration | |
| recursiveAssertionDriver | back to summary |
|---|---|
| private final RecursiveAssertionDriver recursiveAssertionDriver | |
| RecursiveAssertionAssert | back to summary |
|---|---|
| public RecursiveAssertionAssert(Object o, RecursiveAssertionConfiguration recursiveAssertionConfiguration) | |
| allFieldsSatisfy | back to summary |
|---|---|
| public RecursiveAssertionAssert allFieldsSatisfy(Predicate<Object> predicate) Asserts that the given predicate is met for all fields of the object under test recursively (but not the object itself). For example if the object under test is an instance of class A, A has a B field and B a C field then the assertion checks A's B field and B's C field and all C's fields. The recursive algorithm employs cycle detection, so object graphs with cyclic references can safely be asserted over without causing looping. This method enables recursive asserting using default configuration, which means all fields of all objects have the
You can change how the recursive assertion deals with arrays, collections, maps and optionals, see:
It is possible to assert several predicates over the object graph in a row. The classes used in recursive asserting are not thread safe. Care must be taken when running tests in parallel not to run assertions over object graphs that are being shared between tests. Example:
| |
| hasNoNullFields | back to summary |
|---|---|
| public RecursiveAssertionAssert hasNoNullFields() Asserts that none of the fields of the object under test graph (i.e. recursively getting the fields) are null (but not the object itself).
This is a convenience method for a common test, and it is equivalent to Example:
| |
| ignoringAllNullFields | back to summary |
|---|---|
| public RecursiveAssertionAssert ignoringAllNullFields() Makes the recursive assertion to ignore all null fields.
| |
| ignoringFields | back to summary |
|---|---|
| public RecursiveAssertionAssert ignoringFields(String... fieldsToIgnore) Makes the recursive assertion to ignore the specified fields in the object under test. When a field is ignored, all its fields are ignored too. Example:
| |
| ignoringFieldsMatchingRegexes | back to summary |
|---|---|
| public RecursiveAssertionAssert ignoringFieldsMatchingRegexes(String... regexes) Makes the recursive assertion to ignore the fields matching the specified regexes in the object under test. When a field is ignored, all its fields are ignored too. Example:
| |
| ignoringFieldsOfTypes | back to summary |
|---|---|
| public RecursiveAssertionAssert ignoringFieldsOfTypes(Class<?>... typesToIgnore) 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. When a field is ignored, all its fields are ignored too. Example:
| |
| ignoringPrimitiveFields | back to summary |
|---|---|
| public RecursiveAssertionAssert ignoringPrimitiveFields() Make the recursive assertion not to run the For example, consider the following class:
By default, the assertion being applied recursively will be applied to
If you elect to assert over primitives then it is your own responsibility as a developer to ensure that your
| |
| withCollectionAssertionPolicy | back to summary |
|---|---|
| public RecursiveAssertionAssert withCollectionAssertionPolicy(RecursiveAssertionConfiguration. Makes the recursive assertion to use the specified
See
| |
| withIntrospectionStrategy | back to summary |
|---|---|
| public RecursiveAssertionAssert withIntrospectionStrategy(RecursiveAssertionIntrospectionStrategy introspectionStrategy) Defines how objects are introspected in the recursive assertion.
Default to
| |
| withMapAssertionPolicy | back to summary |
|---|---|
| public RecursiveAssertionAssert withMapAssertionPolicy(RecursiveAssertionConfiguration. Makes the recursive assertion to use the specified
See
| |
| withOptionalAssertionPolicy | back to summary |
|---|---|
| public RecursiveAssertionAssert withOptionalAssertionPolicy(RecursiveAssertionConfiguration. Makes the recursive assertion to use the specified
See
| |