/** * A shortcut to the frequently used <code>hasItemInArray(equalTo(x))</code>. * For example: * <pre>assertThat(hasItemInArray(x))</pre> * instead of: * <pre>assertThat(hasItemInArray(equalTo(x)))</pre> * * @param element * the element that should be present in examined arrays */ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(T element) { return ArrayMatching.hasItemInArray(element); }
/** * Creates a matcher for arrays that matches when the examined array contains at least one item * that is matched by the specified <code>elementMatcher</code>. Whilst matching, the traversal * of the examined array will stop as soon as a matching element is found. * For example: * <pre>assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))</pre> * * @param elementMatcher * the matcher to apply to elements in examined arrays */ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.Matcher<? super T> elementMatcher) { return ArrayMatching.hasItemInArray(elementMatcher); }
/** * A shortcut to the frequently used <code>hasItemInArray(equalTo(x))</code>. * For example: * <pre>assertThat(hasItemInArray(x))</pre> * instead of: * <pre>assertThat(hasItemInArray(equalTo(x)))</pre> * * @param element * the element that should be present in examined arrays */ public static <T> Matcher<T[]> hasItemInArray(T element) { return hasItemInArray(equalTo(element)); }
@Override protected Matcher<?> createMatcher() { return hasItemInArray("irrelevant"); }
public void testMatchesAnArrayThatContainsAnElementMatchingTheGivenMatcher() { assertMatches("should matches array that contains 'a'", hasItemInArray("a"), new String[]{"a", "b", "c"}); }
public void testDoesNotMatchNull() { assertDoesNotMatch("should not matches null", hasItemInArray("a"), null); }
public void testDoesNotMatchAnArrayThatDoesntContainAnElementMatchingTheGivenMatcher() { assertDoesNotMatch("should not matches array that doesn't contain 'a'", hasItemInArray("a"), new String[]{"b", "c"}); assertDoesNotMatch("should not matches empty array", hasItemInArray("a"), new String[0]); assertMismatchDescription( "mismatches were: [<3> was greater than <2>, <4> was greater than <2>, <5> was greater than <2>]", hasItemInArray(lessThan(2)), new Integer[] {3, 4, 5}); }
public void testHasAReadableDescription() { assertDescription("an array containing a value less than <2>", hasItemInArray(lessThan(2))); }
/** * Creates a matcher for arrays that matches when the examined array contains at least one item * that is matched by the specified <code>elementMatcher</code>. Whilst matching, the traversal * of the examined array will stop as soon as a matching element is found. * For example: * <pre>assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))</pre> * * @param elementMatcher * the matcher to apply to elements in examined arrays */ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.Matcher<? super T> elementMatcher) { return ArrayMatching.hasItemInArray(elementMatcher); }
/** * A shortcut to the frequently used <code>hasItemInArray(equalTo(x))</code>. * For example: * <pre>assertThat(hasItemInArray(x))</pre> * instead of: * <pre>assertThat(hasItemInArray(equalTo(x)))</pre> * * @param element * the element that should be present in examined arrays */ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(T element) { return ArrayMatching.hasItemInArray(element); }
/** * A shortcut to the frequently used <code>hasItemInArray(equalTo(x))</code>. * For example: * <pre>assertThat(hasItemInArray(x))</pre> * instead of: * <pre>assertThat(hasItemInArray(equalTo(x)))</pre> * * @param element * the element that should be present in examined arrays */ public static <T> Matcher<T[]> hasItemInArray(T element) { return hasItemInArray(equalTo(element)); }