Top Fields Constructors Methods
org.hamcrest.collection

public Class IsMapContaining<K, V>

extends TypeSafeMatcher<Map<? extends K, ? extends V>>
Class Inheritance
Imports
org.hamcrest.Description, .Factory, .Matcher, .TypeSafeMatcher, java.util.Map, .Map.Entry

Field Summary

Modifier and TypeField and Description
private final Matcher<? super K>
private final Matcher<? super V>

Constructor Summary

AccessConstructor and Description
public
IsMapContaining(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)

Method Summary

Modifier and TypeMethod and Description
public void
describeMismatchSafely(Map<? extends K, ? extends V> map, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this.
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static <K, V> Matcher<Map<? extends K, ? extends V>>
hasEntry(Matcher<? super K>
the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry
keyMatcher
,
Matcher<? super V>
the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
valueMatcher
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one entry whose key satisfies the specified keyMatcher and whose value satisfies the specified valueMatcher.

public static <K, V> Matcher<Map<? extends K, ? extends V>>
hasEntry(K
the key that, in combination with the value, must be describe at least one entry
key
,
V
the value that, in combination with the key, must be describe at least one entry
value
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one entry whose key equals the specified key and whose value equals the specified value.

public static <K> Matcher<Map<? extends K, ?>>
hasKey(Matcher<? super K>
the matcher that must be satisfied by at least one key
keyMatcher
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one key that satisfies the specified matcher.

public static <K> Matcher<Map<? extends K, ?>>
hasKey(K
the key that satisfying maps must contain
key
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one key that is equal to the specified key.

public static <V> Matcher<Map<?, ? extends V>>
hasValue(Matcher<? super V>
the matcher that must be satisfied by at least one value
valueMatcher
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one value that satisfies the specified valueMatcher.

public static <V> Matcher<Map<?, ? extends V>>
hasValue(V
the value that satisfying maps must contain
value
)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one value that is equal to the specified value.

public boolean
matchesSafely(Map<? extends K, ? extends V> map)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this.
Inherited from org.hamcrest.TypeSafeMatcher:
describeMismatchmatches

Field Detail

keyMatcherback to summary
private final Matcher<? super K> keyMatcher
valueMatcherback to summary
private final Matcher<? super V> valueMatcher

Constructor Detail

IsMapContainingback to summary
public IsMapContaining(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)

Method Detail

describeMismatchSafelyback to summary
public void describeMismatchSafely(Map<? extends K, ? extends V> map, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Doc from org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

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:Description

The description to be built or appended to.

Annotations
@Override
hasEntryback to summary
public static <K, V> Matcher<Map<? extends K, ? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one entry whose key satisfies the specified keyMatcher and whose value satisfies the specified valueMatcher.

For example:

assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))
Parameters
keyMatcher:Matcher<? super K>

the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry

valueMatcher:Matcher<? super V>

the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry

Annotations
@Factory
hasEntryback to summary
public static <K, V> Matcher<Map<? extends K, ? extends V>> hasEntry(K key, V value)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one entry whose key equals the specified key and whose value equals the specified value.

For example:

assertThat(myMap, hasEntry("bar", "foo"))
Parameters
key:K

the key that, in combination with the value, must be describe at least one entry

value:V

the value that, in combination with the key, must be describe at least one entry

Annotations
@Factory
hasKeyback to summary
public static <K> Matcher<Map<? extends K, ?>> hasKey(Matcher<? super K> keyMatcher)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one key that satisfies the specified matcher.

For example:

assertThat(myMap, hasKey(equalTo("bar")))
Parameters
keyMatcher:Matcher<? super K>

the matcher that must be satisfied by at least one key

Annotations
@Factory
hasKeyback to summary
public static <K> Matcher<Map<? extends K, ?>> hasKey(K key)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one key that is equal to the specified key.

For example:

assertThat(myMap, hasKey("bar"))
Parameters
key:K

the key that satisfying maps must contain

Annotations
@Factory
hasValueback to summary
public static <V> Matcher<Map<?, ? extends V>> hasValue(Matcher<? super V> valueMatcher)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one value that satisfies the specified valueMatcher.

For example:

assertThat(myMap, hasValue(equalTo("foo")))
Parameters
valueMatcher:Matcher<? super V>

the matcher that must be satisfied by at least one value

Annotations
@Factory
hasValueback to summary
public static <V> Matcher<Map<?, ? extends V>> hasValue(V value)

Creates a matcher for java.util.Maps matching when the examined java.util.Map contains at least one value that is equal to the specified value.

For example:

assertThat(myMap, hasValue("foo"))
Parameters
value:V

the value that satisfying maps must contain

Annotations
@Factory
matchesSafelyback to summary
public boolean matchesSafely(Map<? extends K, ? extends V> map)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override