T
- the type of the object to testpublic abstract class AssertionMatcher<T>
extends org.hamcrest.BaseMatcher<T>
Matcher
that reuses AssertJ assertions.
Overriding classes should only implement assertion(Object)
method as
Matcher.matches(Object)
and SelfDescribing.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);
}
})
);
Constructor and Description |
---|
AssertionMatcher() |
Modifier and Type | Method and Description |
---|---|
abstract void |
assertion(T actual)
Perform the assertions implemented in this method when the
AssertionMatcher is used as an Hamcrest Matcher . |
void |
describeTo(org.hamcrest.Description description) |
boolean |
matches(Object argument) |
public boolean matches(Object argument)
public abstract void assertion(T actual) throws AssertionError
AssertionMatcher
is used as an Hamcrest Matcher
.
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);
}
})
);
actual
- assertion objectAssertionError
- if the assertion object fails assertionpublic void describeTo(org.hamcrest.Description description)
Copyright © 2014–2019 AssertJ. All rights reserved.