Class IsMapWithSize<K,​V>

  • All Implemented Interfaces:
    Matcher<java.util.Map<? extends K,​? extends V>>, SelfDescribing

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

      • IsMapWithSize

        public IsMapWithSize​(Matcher<? super java.lang.Integer> sizeMatcher)
    • Method Detail

      • featureValueOf

        protected java.lang.Integer featureValueOf​(java.util.Map<? extends K,​? extends V> actual)
        Description copied from class: FeatureMatcher
        Implement this to extract the interesting feature.
        Specified by:
        featureValueOf in class FeatureMatcher<java.util.Map<? extends K,​? extends V>,​java.lang.Integer>
        Parameters:
        actual - the target object
        Returns:
        the feature to be matched
      • aMapWithSize

        public static <K,​V> Matcher<java.util.Map<? extends K,​? extends V>> aMapWithSize​(Matcher<? super java.lang.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))))
        Parameters:
        sizeMatcher - a matcher for the size of an examined Map
      • aMapWithSize

        public static <K,​V> Matcher<java.util.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)))
        Parameters:
        size - the expected size of an examined Map
      • anEmptyMap

        public static <K,​V> Matcher<java.util.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()))