Top Fields Constructors Methods
org.hamcrest.core

public Class IsIterableContaining<T>

extends TypeSafeDiagnosingMatcher<Iterable<? super T>>
Class Inheritance
Imports
org.hamcrest.Description, .Matcher, .TypeSafeDiagnosingMatcher, java.util.ArrayList, .List

Field Summary

Modifier and TypeField and Description
private final Matcher<? super T>

Constructor Summary

AccessConstructor and Description
public
IsIterableContaining(Matcher<? super T> elementMatcher)

Method Summary

Modifier and TypeMethod and Description
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static <T> Matcher<Iterable<? super T>>
hasItem(Matcher<? super T>
the matcher to apply to items provided by the examined Iterable
itemMatcher
)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is matched by the specified itemMatcher.

public static <T> Matcher<Iterable<? super T>>
hasItem(T
the item to compare against the items provided by the examined Iterable
item
)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is equal to the specified item.

public static <T> Matcher<Iterable<T>>
hasItems(Matcher<? super T>...
the matchers to apply to items provided by the examined Iterable
itemMatchers
)

Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is matched by the corresponding matcher from the specified itemMatchers.

public static <T> Matcher<Iterable<T>>
hasItems(T...
the items to compare against the items provided by the examined Iterable
items
)

Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is equal to the corresponding item from the specified items.

private boolean
isEmpty(Iterable<? super T> iterable)

protected boolean
matchesSafely(Iterable<? super T> collection, Description mismatchDescription)

Implements abstract org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Subclasses should implement this.
Inherited from org.hamcrest.TypeSafeDiagnosingMatcher:
describeMismatchmatches

Field Detail

elementMatcherback to summary
private final Matcher<? super T> elementMatcher

Constructor Detail

IsIterableContainingback to summary
public IsIterableContaining(Matcher<? super T> elementMatcher)

Method Detail

describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
hasItemback to summary
public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is matched by the specified itemMatcher. Whilst matching, the traversal of the examined Iterable will stop as soon as a matching item is found. For example:

assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
Parameters
itemMatcher:Matcher<? super T>

the matcher to apply to items provided by the examined Iterable

hasItemback to summary
public static <T> Matcher<Iterable<? super T>> hasItem(T item)

Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is equal to the specified item. Whilst matching, the traversal of the examined Iterable will stop as soon as a matching item is found. For example:

assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
Parameters
item:T

the item to compare against the items provided by the examined Iterable

hasItemsback to summary
public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers)

Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is matched by the corresponding matcher from the specified itemMatchers. Whilst matching, each traversal of the examined Iterable will stop as soon as a matching item is found. For example:

assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
Parameters
itemMatchers:Matcher<? super T>[]

the matchers to apply to items provided by the examined Iterable

Annotations
@SafeVarargs
hasItemsback to summary
public static <T> Matcher<Iterable<T>> hasItems(T... items)

Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is equal to the corresponding item from the specified items. Whilst matching, each traversal of the examined Iterable will stop as soon as a matching item is found. For example:

assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
Parameters
items:T[]

the items to compare against the items provided by the examined Iterable

Annotations
@SafeVarargs
isEmptyback to summary
private boolean isEmpty(Iterable<? super T> iterable)
matchesSafelyback to summary
protected boolean matchesSafely(Iterable<? super T> collection, Description mismatchDescription)

Implements abstract org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override