Package org.hamcrest.collection
Class IsMapContaining<K,V>
java.lang.Object
org.hamcrest.BaseMatcher<Map<? extends K,? extends V>>
org.hamcrest.TypeSafeMatcher<Map<? extends K,? extends V>>
org.hamcrest.collection.IsMapContaining<K,V>
- Type Parameters:
K- the type of the map keysV- the type of the map values
- All Implemented Interfaces:
Matcher<Map<? extends K,,? extends V>> SelfDescribing
Matches if map keys, values or entries match the value matchers.
-
Constructor Summary
ConstructorsConstructorDescriptionIsMapContaining(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher) Constructor, best called from one of the static factory methods (hasKey,hasValue, orhasEntry). -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeMismatchSafely(Map<? extends K, ? extends V> map, Description mismatchDescription) Describe the mismatch.voiddescribeTo(Description description) Generates a description of the object.hasEntry(K key, V value) hasKey(K key) hasValue(V value) booleanmatchesSafely(Map<? extends K, ? extends V> map) Check if the item matches.Methods inherited from class org.hamcrest.TypeSafeMatcher
describeMismatch, matchesMethods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Constructor Details
-
IsMapContaining
Constructor, best called from one of the static factory methods (hasKey,hasValue, orhasEntry).- Parameters:
keyMatcher- matcher for expected keysvalueMatcher- matcher for expected values- See Also:
-
-
Method Details
-
matchesSafely
Description copied from class:TypeSafeMatcherCheck if the item matches. The item will already have been checked for the specific type and will never be null. Subclasses should implement this.- Specified by:
matchesSafelyin classTypeSafeMatcher<Map<? extends K,? extends V>> - Parameters:
map- the type safe item to match against.- Returns:
- boolean true/false depending if item matches matcher.
-
describeMismatchSafely
public void describeMismatchSafely(Map<? extends K, ? extends V> map, Description mismatchDescription) Description copied from class:TypeSafeMatcherDescribe the mismatch. The item will already have been checked for the specific type and will never be null. Subclasses should override this.- Overrides:
describeMismatchSafelyin classTypeSafeMatcher<Map<? extends K,? extends V>> - Parameters:
map- the type safe item to match against.mismatchDescription- the mismatch description.
-
describeTo
Description copied from interface:SelfDescribingGenerates a description of the object. The description may be part of 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<Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher) Creates a matcher forMaps matching when the examinedMapcontains at least one entry whose key satisfies the specifiedkeyMatcherand whose value satisfies the specifiedvalueMatcher. For example:assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))- Type Parameters:
K- the map key type.V- the map value type.- 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- Returns:
- The matcher.
-
hasEntry
Creates a matcher forMaps matching when the examinedMapcontains at least one entry whose key equals the specifiedkeyand whose value equals the specifiedvalue. For example:assertThat(myMap, hasEntry("bar", "foo"))- Type Parameters:
K- the map key type.V- the map value type.- 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- Returns:
- The matcher.
-
hasKey
Creates a matcher forMaps matching when the examinedMapcontains at least one key that satisfies the specified matcher. For example:assertThat(myMap, hasKey(equalTo("bar")))- Type Parameters:
K- the map key type.- Parameters:
keyMatcher- the matcher that must be satisfied by at least one key- Returns:
- The matcher.
-
hasKey
Creates a matcher forMaps matching when the examinedMapcontains at least one key that is equal to the specified key. For example:assertThat(myMap, hasKey("bar"))- Type Parameters:
K- the map key type.- Parameters:
key- the key that satisfying maps must contain- Returns:
- The matcher.
-
hasValue
Creates a matcher forMaps matching when the examinedMapcontains at least one value that satisfies the specified valueMatcher. For example:assertThat(myMap, hasValue(equalTo("foo")))- Type Parameters:
V- the value type.- Parameters:
valueMatcher- the matcher that must be satisfied by at least one value- Returns:
- The matcher.
-
hasValue
Creates a matcher forMaps matching when the examinedMapcontains at least one value that is equal to the specified value. For example:assertThat(myMap, hasValue("foo"))- Type Parameters:
V- the value type.- Parameters:
value- the value that satisfying maps must contain- Returns:
- The matcher.
-