public class MapContentMatchers<T,V>
extends org.hamcrest.BaseMatcher<T>
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<java.util.Map<? super T,? super V>> |
hasAllEntries(java.util.Map<T,V> entries) |
static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> |
hasEntry(T key,
org.hamcrest.Matcher<V> valueMatcher) |
static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> |
hasEntry(T key,
V value) |
static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> |
hasKey(T key) |
boolean |
matches(java.lang.Object item)
Method made final to prevent accidental override.
|
boolean |
matchesSafely(java.util.Map<? super T,? super V> item)
Subclasses should implement this.
|
public boolean matchesSafely(java.util.Map<? super T,? super V> item)
public void describeTo(org.hamcrest.Description description)
public static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> hasEntry(T key, V value)
public static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> hasEntry(T key, org.hamcrest.Matcher<V> valueMatcher)
public static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> hasKey(T key)
public static <T,V> org.hamcrest.Matcher<java.util.Map<? super T,? super V>> hasAllEntries(java.util.Map<T,V> entries)
public final boolean matches(java.lang.Object item)
BaseMatcher
.