Class IsIterableWithSize<E>

Type Parameters:
E - the iterable element type
All Implemented Interfaces:
Matcher<Iterable<E>>, SelfDescribing

public class IsIterableWithSize<E> extends FeatureMatcher<Iterable<E>,Integer>
Matches if iterable size satisfies a size matcher.
  • Constructor Details

  • Method Details

    • featureValueOf

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

      public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super Integer> sizeMatcher)
      Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields an item count that satisfies the specified matcher. For example:
      assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))
      Type Parameters:
      E - the matcher type.
      Parameters:
      sizeMatcher - a matcher for the number of items that should be yielded by an examined Iterable
      Returns:
      The matcher.
    • iterableWithSize

      public static <E> Matcher<Iterable<E>> iterableWithSize(int size)
      Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields an item count that is equal to the specified size argument. For example:
      assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))
      Type Parameters:
      E - the matcher type.
      Parameters:
      size - the number of items that should be yielded by an examined Iterable
      Returns:
      The matcher.