Class IsCollectionWithSize<E>

java.lang.Object
org.hamcrest.BaseMatcher<Collection<? extends E>>
org.hamcrest.TypeSafeDiagnosingMatcher<Collection<? extends E>>
org.hamcrest.FeatureMatcher<Collection<? extends E>,Integer>
org.hamcrest.collection.IsCollectionWithSize<E>
Type Parameters:
E - the collection element type
All Implemented Interfaces:
Matcher<Collection<? extends E>>, SelfDescribing

public class IsCollectionWithSize<E> extends FeatureMatcher<Collection<? extends E>,Integer>
Matches if collection size satisfies a nested matcher.
  • Constructor Details

  • Method Details

    • featureValueOf

      protected Integer featureValueOf(Collection<? extends E> actual)
      Description copied from class: FeatureMatcher
      Implement this to extract the interesting feature.
      Specified by:
      featureValueOf in class FeatureMatcher<Collection<? extends E>,Integer>
      Parameters:
      actual - the target object
      Returns:
      the feature to be matched
    • hasSize

      public static <E> Matcher<Collection<? extends E>> hasSize(Matcher<? super Integer> sizeMatcher)
      Creates a matcher for Collections that matches when the size() method returns a value that satisfies the specified matcher. For example:
      assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))
      Type Parameters:
      E - the matcher type.
      Parameters:
      sizeMatcher - a matcher for the size of an examined Collection
      Returns:
      The matcher.
    • hasSize

      public static <E> Matcher<Collection<? extends E>> hasSize(int size)
      Creates a matcher for Collections that matches when the size() method returns a value equal to the specified size. For example:
      assertThat(Arrays.asList("foo", "bar"), hasSize(2))
      Type Parameters:
      E - the matcher type.
      Parameters:
      size - the expected size of an examined Collection
      Returns:
      The matcher.