Matcher that reuses AssertJ assertions.
Overriding classes should only implement AssertionMatcher#assertion(Object) method as
Matcher#matches(Object) and Matcher#describeTo(Description) are provided.
If the matcher fails, the description will contain the stacktrace of the first failed assertion.
Example with Mockito:
verify(customerRepository).save(argThat(new AssertionMatcher<Customer>() {
@Override
public void assertion(Customer actual) throws AssertionError {
assertThat(actual).hasName("John")
.hasAge(30);
}
})
);
| Modifier and Type | Field and Description |
|---|---|
| private AssertionError |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void | assertion(T
assertion object actual)Perform the assertions implemented in this method when the |
| public void | describeTo(Description
The description to be built or appended to. description)Implements org. |
| public boolean | matches(Object
the object against which the matcher is evaluated. argument)Implements org. |
| firstError | back to summary |
|---|---|
| private AssertionError firstError | |
| AssertionMatcher | back to summary |
|---|---|
| public AssertionMatcher() | |
| assertion | back to summary |
|---|---|
| public abstract void assertion(T actual) throws AssertionError Perform the assertions implemented in this method when the Example with Mockito:
| |
| describeTo | back to summary |
|---|---|
| public void describeTo(Description description) Implements org. Doc from org. Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.
| |
| matches | back to summary |
|---|---|
| public boolean matches(Object argument) Implements org. Doc from org. Evaluates the matcher for argument item. This method matches against Object, instead of the generic type T. This is because the caller of the Matcher does not know at runtime what the type is (because of type erasure with Java generics). It is down to the implementations to check the correct type.
| |