Class IsCollectionWithSize<E>

  • All Implemented Interfaces:
    org.hamcrest.Matcher<java.util.Collection<? extends E>>, org.hamcrest.SelfDescribing

    public class IsCollectionWithSize<E>
    extends CollectionMatcher<java.util.Collection<? extends E>>
    Matches if collection size satisfies a nested matcher.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher  
    • Constructor Summary

      Constructors 
      Constructor Description
      IsCollectionWithSize​(org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void describeTo​(org.hamcrest.Description description)  
      static <E> org.hamcrest.Matcher<? super java.util.Collection<? extends E>> hasSize​(int size)
      This is a shortcut to the frequently used hasSize(equalTo(x)).
      static <E> org.hamcrest.Matcher<? super java.util.Collection<? extends E>> hasSize​(org.hamcrest.Matcher<? super java.lang.Integer> size)
      Does collection size satisfy a given matcher?
      boolean matchesSafely​(java.util.Collection<? extends E> item)  
      • Methods inherited from class org.hamcrest.BaseMatcher

        _dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sizeMatcher

        private final org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher
    • Constructor Detail

      • IsCollectionWithSize

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

      • matchesSafely

        public boolean matchesSafely​(java.util.Collection<? extends E> item)
        Specified by:
        matchesSafely in class CollectionMatcher<java.util.Collection<? extends E>>
      • describeTo

        public void describeTo​(org.hamcrest.Description description)
      • hasSize

        public static <E> org.hamcrest.Matcher<? super java.util.Collection<? extends E>> hasSize​(org.hamcrest.Matcher<? super java.lang.Integer> size)
        Does collection size satisfy a given matcher?
      • hasSize

        public static <E> org.hamcrest.Matcher<? super java.util.Collection<? extends E>> hasSize​(int size)
        This is a shortcut to the frequently used hasSize(equalTo(x)). For example, assertThat(hasSize(equal_to(x))) vs. assertThat(hasSize(x))