org.hamcrest.collection
Class IsArrayContaining<T>

java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.hamcrest.TypeSafeMatcher<T[]>
          extended by org.hamcrest.collection.IsArrayContaining<T>
All Implemented Interfaces:
org.hamcrest.Matcher<T[]>, org.hamcrest.SelfDescribing

public class IsArrayContaining<T>
extends org.hamcrest.TypeSafeMatcher<T[]>

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


Constructor Summary
IsArrayContaining(org.hamcrest.Matcher<? super T> elementMatcher)
           
 
Method Summary
 void describeMismatchSafely(T[] item, org.hamcrest.Description mismatchDescription)
           
 void describeTo(org.hamcrest.Description description)
           
static
<T> org.hamcrest.Matcher<T[]>
hasItemInArray(org.hamcrest.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.
static
<T> org.hamcrest.Matcher<T[]>
hasItemInArray(T element)
          A shortcut to the frequently used hasItemInArray(equalTo(x)).
 boolean matchesSafely(T[] array)
           
 
Methods inherited from class org.hamcrest.TypeSafeMatcher
describeMismatch, matches
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IsArrayContaining

public IsArrayContaining(org.hamcrest.Matcher<? super T> elementMatcher)
Method Detail

matchesSafely

public boolean matchesSafely(T[] array)
Specified by:
matchesSafely in class org.hamcrest.TypeSafeMatcher<T[]>

describeMismatchSafely

public void describeMismatchSafely(T[] item,
                                   org.hamcrest.Description mismatchDescription)
Overrides:
describeMismatchSafely in class org.hamcrest.TypeSafeMatcher<T[]>

describeTo

public void describeTo(org.hamcrest.Description description)

hasItemInArray

public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.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 - the matcher to apply to elements in examined arrays

hasItemInArray

public static <T> org.hamcrest.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 - the element that should be present in examined arrays