/** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified list of matchers. For a positive match, the examined array * must be of the same length as the specified list of matchers. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by the corresponding item in an examined array */ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<org.hamcrest.Matcher<? super E>> itemMatchers) { return ArrayMatching.arrayContaining(itemMatchers); }
/** * Creates a matcher for arrays that matches when each item in the examined array is * logically equal to the corresponding item in the specified items. For a positive match, * the examined array must be of the same length as the number of specified items. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining("foo", "bar"))</pre> * * @param items * the items that must equal the items within an examined array */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContaining(E... items) { return ArrayMatching.arrayContaining(items); }
/** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified matchers. For a positive match, the examined array * must be of the same length as the number of specified matchers. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))</pre> * * @param itemMatchers * the matchers that must be satisfied by the items in the examined array */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher<? super E>... itemMatchers) { return ArrayMatching.arrayContaining(itemMatchers); }
/** * Creates a matcher for arrays that matches when each item in the examined array is * logically equal to the corresponding item in the specified items. For a positive match, * the examined array must be of the same length as the number of specified items. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))</pre> * * @param items * the items that must equal the items within an examined array */ @SafeVarargs public static <E> Matcher<E[]> arrayContaining(E... items) { return arrayContaining(asEqualMatchers(items)); } /**
/** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified matchers. For a positive match, the examined array * must be of the same length as the number of specified matchers. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))</pre> * * @param itemMatchers * the matchers that must be satisfied by the items in the examined array */ @SafeVarargs public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers) { //required for JDK 1.6 //noinspection RedundantTypeArguments final List<Matcher<? super E>> nullSafeWithExplicitTypeMatchers = NullSafety.<E>nullSafe(itemMatchers); return arrayContaining(nullSafeWithExplicitTypeMatchers); }
@SuppressWarnings("unchecked") @Override protected Matcher<?> createMatcher() { return arrayContaining(equalTo(1), equalTo(2)); }
@SuppressWarnings("unchecked") public void testAppliesMatchersInOrder() { assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); }
@SuppressWarnings("unchecked") public void testHasAReadableDescription() { assertDescription("[<1>, <2>]", arrayContaining(equalTo(1), equalTo(2))); }
public void testMatchesItemsInOrder() { assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); assertMatches("single", arrayContaining(1), new Integer[] {1}); }
public void testCanHandleNullValuesInAnArray() { assertMatches("with nulls", arrayContaining(null, null), new Object[]{null, null}); } }
public void testMismatchesItemsInOrder() { Matcher<Integer[]> matcher = arrayContaining(1, 2, 3); assertMismatchDescription("was null", matcher, null); assertMismatchDescription("no item was <1>", matcher, new Integer[] {}); assertMismatchDescription("no item was <2>", matcher, new Integer[] {1}); assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); }
/** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified list of matchers. For a positive match, the examined array * must be of the same length as the specified list of matchers. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by the corresponding item in an examined array */ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<org.hamcrest.Matcher<? super E>> itemMatchers) { return ArrayMatching.arrayContaining(itemMatchers); }
/** * Creates a matcher for arrays that matches when each item in the examined array is * logically equal to the corresponding item in the specified items. For a positive match, * the examined array must be of the same length as the number of specified items. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining("foo", "bar"))</pre> * * @param items * the items that must equal the items within an examined array */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContaining(E... items) { return ArrayMatching.arrayContaining(items); }
/** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified matchers. For a positive match, the examined array * must be of the same length as the number of specified matchers. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))</pre> * * @param itemMatchers * the matchers that must be satisfied by the items in the examined array */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher<? super E>... itemMatchers) { return ArrayMatching.arrayContaining(itemMatchers); }
/** * Creates a matcher for arrays that matches when each item in the examined array is * logically equal to the corresponding item in the specified items. For a positive match, * the examined array must be of the same length as the number of specified items. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))</pre> * * @param items * the items that must equal the items within an examined array */ @SafeVarargs public static <E> Matcher<E[]> arrayContaining(E... items) { return arrayContaining(asEqualMatchers(items)); } /**
/** * Creates a matcher for arrays that matches when each item in the examined array satisfies the * corresponding matcher in the specified matchers. For a positive match, the examined array * must be of the same length as the number of specified matchers. * For example: * <pre>assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))</pre> * * @param itemMatchers * the matchers that must be satisfied by the items in the examined array */ @SafeVarargs public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers) { //required for JDK 1.6 //noinspection RedundantTypeArguments final List<Matcher<? super E>> nullSafeWithExplicitTypeMatchers = NullSafety.<E>nullSafe(itemMatchers); return arrayContaining(nullSafeWithExplicitTypeMatchers); }