public class MockitoHamcrest extends Object
Before implementing or reusing an existing hamcrest matcher please read
how to deal with sophisticated argument matching in ArgumentMatcher.
Mockito 2.0 was decoupled from Hamcrest to avoid version incompatibilities
that have impacted our users in past. Mockito offers a dedicated API to match arguments
via ArgumentMatcher.
Hamcrest integration is provided so that users can take advantage of existing Hamcrest matchers.
Example:
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
//stubbing
when(mock.giveMe(argThat(new MyHamcrestMatcher())));
//verification
verify(mock).giveMe(argThat(new MyHamcrestMatcher()));
| Constructor and Description |
|---|
MockitoHamcrest() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
argThat(org.hamcrest.Matcher<T> matcher)
Allows matching arguments with hamcrest matchers.
|
public static <T> T argThat(org.hamcrest.Matcher<T> matcher)
See examples in javadoc for MockitoHamcrest class
matcher - decides whether argument matchesnull or default value for primitive (0, false, etc.)