Top Description Fields Constructors Methods
org.hamcrest.collection

public Class IsArrayContaining<T>

extends TypeSafeMatcher<T[]>
Class Inheritance
Imports
java.util.Arrays, org.hamcrest.Description, .Matcher, .Factory, .TypeSafeMatcher

Matches if an array contains an item satisfying a nested matcher.

Field Summary

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

Constructor Summary

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

Method Summary

Modifier and TypeMethod and Description
public void
describeMismatchSafely(T[] item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this.
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<T[]>
hasItemInArray(Matcher<? super T>
the matcher to apply to elements in examined arrays
elementMatcher
)

Creates a matcher for arrays that matches when the examined array contains at least one item that is matched by the specified elementMatcher.

public static <T> Matcher<T[]>
hasItemInArray(T
the element that should be present in examined arrays
element
)

A shortcut to the frequently used hasItemInArray(equalTo(x)).

public boolean
matchesSafely(T[] array)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

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

Field Detail

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

Constructor Detail

IsArrayContainingback to summary
public IsArrayContaining(Matcher<? super T> elementMatcher)

Method Detail

describeMismatchSafelyback to summary
public void describeMismatchSafely(T[] item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Doc from org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

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

Annotations
@Override
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
hasItemInArrayback to summary
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher)

Creates a matcher for arrays that matches when the examined array contains at least one item that is matched by the specified elementMatcher. Whilst matching, the traversal of the examined array will stop as soon as a matching element is found.

For example:

assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))
Parameters
elementMatcher:Matcher<? super T>

the matcher to apply to elements in examined arrays

Annotations
@Factory
hasItemInArrayback to summary
public static <T> Matcher<T[]> hasItemInArray(T element)

A shortcut to the frequently used hasItemInArray(equalTo(x)).

For example:

assertThat(hasItemInArray(x))
instead of:
assertThat(hasItemInArray(equalTo(x)))
Parameters
element:T

the element that should be present in examined arrays

Annotations
@Factory
matchesSafelyback to summary
public boolean matchesSafely(T[] array)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeMatcher.matchesSafely.

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

Annotations
@Override