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

public final class IsMapWithSize<K,V> extends FeatureMatcher<Map<? extends K,? extends V>,Integer>
Matches if map size satisfies a nested matcher.
  • Constructor Details

  • Method Details

    • featureValueOf

      protected Integer featureValueOf(Map<? extends K,? extends V> actual)
      Description copied from class: FeatureMatcher
      Implement this to extract the interesting feature.
      Specified by:
      featureValueOf in class FeatureMatcher<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 for Maps that matches when the size() 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 examined Map
      Returns:
      The matcher.
    • aMapWithSize

      public static <K, V> Matcher<Map<? extends K,? extends V>> aMapWithSize(int size)
      Creates a matcher for Maps that matches when the size() method returns a value equal to the specified size. 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 examined Map
      Returns:
      The matcher.
    • anEmptyMap

      public static <K, V> Matcher<Map<? extends K,? extends V>> anEmptyMap()
      Creates a matcher for Maps that matches when the size() method returns zero. For example:
      assertThat(myMap, is(anEmptyMap()))
      Type Parameters:
      K - the map key type.
      V - the map value type.
      Returns:
      The matcher.