Package org.assertj.core.matcher
Class AssertionMatcher<T>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.assertj.core.matcher.AssertionMatcher<T>
- Type Parameters:
T
- the type of the object to test
- All Implemented Interfaces:
org.hamcrest.Matcher<T>
,org.hamcrest.SelfDescribing
public abstract class AssertionMatcher<T>
extends org.hamcrest.BaseMatcher<T>
Generic Hamcrest
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);
}
})
);
- Since:
- 2.7.0 / 3.7.0
- Author:
- Tomasz KalkosiĆski
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
Perform the assertions implemented in this method when theAssertionMatcher
is used as an HamcrestMatcher
.void
describeTo
(org.hamcrest.Description description) boolean
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
-
Constructor Details
-
AssertionMatcher
public AssertionMatcher()
-
-
Method Details
-
matches
-
assertion
Perform the assertions implemented in this method when theAssertionMatcher
is used as an HamcrestMatcher
. 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); } }) );
- Parameters:
actual
- assertion object- Throws:
AssertionError
- if the assertion object fails assertion
-
describeTo
public void describeTo(org.hamcrest.Description description)
-