Package org.hamcrest.collection
Class IsMapContaining<K,V>
- java.lang.Object
-
- org.hamcrest.BaseMatcher<T>
-
- org.hamcrest.TypeSafeMatcher<java.util.Map<? extends K,? extends V>>
-
- org.hamcrest.collection.IsMapContaining<K,V>
-
- All Implemented Interfaces:
Matcher<java.util.Map<? extends K,? extends V>>
,SelfDescribing
public class IsMapContaining<K,V> extends TypeSafeMatcher<java.util.Map<? extends K,? extends V>>
-
-
Constructor Summary
Constructors Constructor Description IsMapContaining(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
describeMismatchSafely(java.util.Map<? extends K,? extends V> map, Description mismatchDescription)
Subclasses should override this.void
describeTo(Description description)
Generates a description of the object.static <K,V>
Matcher<java.util.Map<? extends K,? extends V>>hasEntry(K key, V value)
Creates a matcher forMap
s matching when the examinedMap
contains at least one entry whose key equals the specifiedkey
and whose value equals the specifiedvalue
.static <K,V>
Matcher<java.util.Map<? extends K,? extends V>>hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)
Creates a matcher forMap
s matching when the examinedMap
contains at least one entry whose key satisfies the specifiedkeyMatcher
and whose value satisfies the specifiedvalueMatcher
.static <K> Matcher<java.util.Map<? extends K,?>>
hasKey(K key)
Creates a matcher forMap
s matching when the examinedMap
contains at least one key that is equal to the specified key.static <K> Matcher<java.util.Map<? extends K,?>>
hasKey(Matcher<? super K> keyMatcher)
Creates a matcher forMap
s matching when the examinedMap
contains at least one key that satisfies the specified matcher.static <V> Matcher<java.util.Map<?,? extends V>>
hasValue(Matcher<? super V> valueMatcher)
Creates a matcher forMap
s matching when the examinedMap
contains at least one value that satisfies the specified valueMatcher.static <V> Matcher<java.util.Map<?,? extends V>>
hasValue(V value)
Creates a matcher forMap
s matching when the examinedMap
contains at least one value that is equal to the specified value.boolean
matchesSafely(java.util.Map<? extends K,? extends V> map)
Subclasses should implement this.-
Methods inherited from class org.hamcrest.TypeSafeMatcher
describeMismatch, matches
-
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
-
-
-
-
Method Detail
-
matchesSafely
public boolean matchesSafely(java.util.Map<? extends K,? extends V> map)
Description copied from class:TypeSafeMatcher
Subclasses should implement this. The item will already have been checked for the specific type and will never be null.- Specified by:
matchesSafely
in classTypeSafeMatcher<java.util.Map<? extends K,? extends V>>
-
describeMismatchSafely
public void describeMismatchSafely(java.util.Map<? extends K,? extends V> map, Description mismatchDescription)
Description copied from class:TypeSafeMatcher
Subclasses should override this. The item will already have been checked for the specific type and will never be null.- Overrides:
describeMismatchSafely
in classTypeSafeMatcher<java.util.Map<? extends K,? extends V>>
-
describeTo
public void describeTo(Description description)
Description copied from interface:SelfDescribing
Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.- Parameters:
description
- The description to be built or appended to.
-
hasEntry
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)
Creates a matcher forMap
s matching when the examinedMap
contains at least one entry whose key satisfies the specifiedkeyMatcher
and whose value satisfies the specifiedvalueMatcher
. For example:assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))
- Parameters:
keyMatcher
- the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entryvalueMatcher
- the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
-
hasEntry
public static <K,V> Matcher<java.util.Map<? extends K,? extends V>> hasEntry(K key, V value)
Creates a matcher forMap
s matching when the examinedMap
contains at least one entry whose key equals the specifiedkey
and whose value equals the specifiedvalue
. For example:assertThat(myMap, hasEntry("bar", "foo"))
- Parameters:
key
- the key that, in combination with the value, must be describe at least one entryvalue
- the value that, in combination with the key, must be describe at least one entry
-
hasKey
public static <K> Matcher<java.util.Map<? extends K,?>> hasKey(Matcher<? super K> keyMatcher)
Creates a matcher forMap
s matching when the examinedMap
contains at least one key that satisfies the specified matcher. For example:assertThat(myMap, hasKey(equalTo("bar")))
- Parameters:
keyMatcher
- the matcher that must be satisfied by at least one key
-
hasKey
public static <K> Matcher<java.util.Map<? extends K,?>> hasKey(K key)
Creates a matcher forMap
s matching when the examinedMap
contains at least one key that is equal to the specified key. For example:assertThat(myMap, hasKey("bar"))
- Parameters:
key
- the key that satisfying maps must contain
-
hasValue
public static <V> Matcher<java.util.Map<?,? extends V>> hasValue(Matcher<? super V> valueMatcher)
Creates a matcher forMap
s matching when the examinedMap
contains at least one value that satisfies the specified valueMatcher. For example:assertThat(myMap, hasValue(equalTo("foo")))
- Parameters:
valueMatcher
- the matcher that must be satisfied by at least one value
-
hasValue
public static <V> Matcher<java.util.Map<?,? extends V>> hasValue(V value)
Creates a matcher forMap
s matching when the examinedMap
contains at least one value that is equal to the specified value. For example:assertThat(myMap, hasValue("foo"))
- Parameters:
value
- the value that satisfying maps must contain
-
-