public final class MapContentMatchers<T,V> extends org.hamcrest.TypeSafeMatcher<Map<? super T,? super V>>
Map
.
It is possible to match a single entry by value or matcher like this:
assertThat(map, hasEntry(SOME_KEY, is(SOME_VALUE))); assertThat(map, hasEntry(SOME_KEY, is(String.class))); assertThat(map, hasEntry(SOME_KEY, notNullValue()));
It's also possible to match multiple entries in a map:
Map<String, Object> expectedInMap = new HashMap<String, Object>();
expectedInMap.put(SOME_KEY, SOME_VALUE);
expectedInMap.put(OTHER_KEY, is(OTHER_VALUE));
assertThat(map, hasAllEntries(expectedInMap));
If you only need to verify the existence of a key:
assertThat(map, hasKey(SOME_KEY));
Modifier and Type | Method and Description |
---|---|
void |
describeTo(org.hamcrest.Description description) |
static <T,V> org.hamcrest.Matcher<Map<T,V>> |
hasAllEntries(Map<T,V> entries) |
boolean |
matchesSafely(Map<? super T,? super V> item) |
describeMismatch, describeMismatchSafely, matches