Package org.hamcrest.collection
Class IsMapWithSize<K,V>
java.lang.Object
org.hamcrest.BaseMatcher<Map<? extends K,? extends V>>
org.hamcrest.TypeSafeDiagnosingMatcher<Map<? extends K,? extends V>>
org.hamcrest.FeatureMatcher<Map<? extends K,? extends V>,Integer>
org.hamcrest.collection.IsMapWithSize<K,V>
- Type Parameters:
K- the map key type.V- the map value type.
- All Implemented Interfaces:
Matcher<Map<? extends K,,? extends V>> SelfDescribing
Matches if map size satisfies a nested matcher.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaMapWithSize(int size) Creates a matcher forMaps that matches when thesize()method returns a value equal to the specifiedsize.aMapWithSize(Matcher<? super Integer> sizeMatcher) Creates a matcher forMaps that matches when thesize()method returns a value that satisfies the specified matcher.Creates a matcher forMaps that matches when thesize()method returns zero.protected IntegerfeatureValueOf(Map<? extends K, ? extends V> actual) Implement this to extract the interesting feature.Methods inherited from class org.hamcrest.FeatureMatcher
describeTo, matchesSafelyMethods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matchesMethods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Constructor Details
-
IsMapWithSize
- Parameters:
sizeMatcher- matcher for the expected size of the map
-
-
Method Details
-
featureValueOf
Description copied from class:FeatureMatcherImplement this to extract the interesting feature.- Specified by:
featureValueOfin classFeatureMatcher<Map<? extends K,? extends V>, Integer> - Parameters:
actual- the target object- Returns:
- the feature to be matched
-
aMapWithSize
public static <K,V> Matcher<Map<? extends K,? extends V>> aMapWithSize(Matcher<? super Integer> sizeMatcher) Creates a matcher forMaps that matches when thesize()method returns a value that satisfies the specified matcher. For example:assertThat(myMap, is(aMapWithSize(equalTo(2))))
- Type Parameters:
K- the map key type.V- the map value type.- Parameters:
sizeMatcher- a matcher for the size of an examinedMap- Returns:
- The matcher.
-
aMapWithSize
Creates a matcher forMaps that matches when thesize()method returns a value equal to the specifiedsize. For example:assertThat(myMap, is(aMapWithSize(2)))
- Type Parameters:
K- the map key type.V- the map value type.- Parameters:
size- the expected size of an examinedMap- Returns:
- The matcher.
-
anEmptyMap
Creates a matcher forMaps that matches when thesize()method returns zero. For example:assertThat(myMap, is(anEmptyMap()))
- Type Parameters:
K- the map key type.V- the map value type.- Returns:
- The matcher.
-