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 HamcrestMatcher
that reuses AssertJ assertions.Overriding classes should only implement
assertion(Object)
method asMatcher.matches(Object)
andSelfDescribing.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
-
-
Field Summary
Fields Modifier and Type Field Description private AssertionError
firstError
-
Constructor Summary
Constructors Constructor Description AssertionMatcher()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
assertion(T actual)
Perform the assertions implemented in this method when theAssertionMatcher
is used as an HamcrestMatcher
.void
describeTo(org.hamcrest.Description description)
boolean
matches(Object argument)
-
-
-
Field Detail
-
firstError
private AssertionError firstError
-
-
Method Detail
-
matches
public boolean matches(Object argument)
-
assertion
public abstract void assertion(T actual) throws AssertionError
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)
-
-