/** * <p> * Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified collection of matchers. * For a positive match, the examined array must be of the same length as the specified collection * of matchers. * </p> * <p> * N.B. each matcher in the specified collection will only be used once during a given * examination, so be careful when specifying matchers that may be satisfied by more than * one entry in an examined array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined array */ public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(java.util.Collection<org.hamcrest.Matcher<? super E>> itemMatchers) { return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); }
/** * <p>Creates an order agnostic matcher for arrays that matches when each item in the * examined array is logically equal to one item anywhere in the specified items. * For a positive match, the examined array must be of the same length as the number of * specified items. * </p> * <p>N.B. each of the specified items will only be used once during a given examination, so be * careful when specifying items that may be equal to more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder("bar", "foo"))</pre> * * @param items * the items that must equal the entries of an examined array, in any order */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(E... items) { return ArrayMatching.arrayContainingInAnyOrder(items); }
/** * <p> * Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified matchers. * For a positive match, the examined array must be of the same length as the number of * specified matchers. * </p> * <p> * N.B. each of the specified matchers will only be used once during a given examination, so be * careful when specifying matchers that may be satisfied by more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by an entry in an examined array */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcrest.Matcher<? super E>... itemMatchers) { return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); }
/** * <p> * Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified matchers. * For a positive match, the examined array must be of the same length as the number of * specified matchers. * </p> * <p> * N.B. each of the specified matchers will only be used once during a given examination, so be * careful when specifying matchers that may be satisfied by more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by an entry in an examined array */ @SafeVarargs public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) { return arrayContainingInAnyOrder(asList(itemMatchers)); }
/** * <p>Creates an order agnostic matcher for arrays that matches when each item in the * examined array is logically equal to one item anywhere in the specified items. * For a positive match, the examined array must be of the same length as the number of * specified items. * </p> * <p>N.B. each of the specified items will only be used once during a given examination, so be * careful when specifying items that may be equal to more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))</pre> * * @param items * the items that must equal the entries of an examined array, in any order */ @SafeVarargs public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) { return arrayContainingInAnyOrder(asEqualMatchers(items)); }
@SuppressWarnings("unchecked") @Override protected Matcher<?> createMatcher() { return ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2)); }
@SuppressWarnings("unchecked") public void testAppliesMatchersInAnyOrder() { assertMatches("in order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); assertMatches("out of order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1}); assertMatches("single", ArrayMatching.arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1}); }
@SuppressWarnings("unchecked") public void testHasAReadableDescription() { assertDescription("[<1>, <2>] in any order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2))); assertDescription("[<1>, <2>] in any order", ArrayMatching.arrayContainingInAnyOrder(1, 2)); }
public void testMatchesItemsInAnyOrder() { assertMatches("in order", ArrayMatching.arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3}); assertMatches("out of order", ArrayMatching.arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1}); assertMatches("single", ArrayMatching.arrayContainingInAnyOrder(1), new Integer[] {1}); }
public void testMismatchesItemsInAnyOrder() { Matcher<Integer[]> matcher = ArrayMatching.arrayContainingInAnyOrder(1, 2, 3); assertMismatchDescription("was null", matcher, null); assertMismatchDescription("no item matches: <1>, <2>, <3> in []", matcher, new Integer[] {}); assertMismatchDescription("no item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1}); assertMismatchDescription("not matched: <4>", matcher, new Integer[] {4,3,2,1}); } }
/** * <p> * Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified collection of matchers. * For a positive match, the examined array must be of the same length as the specified collection * of matchers. * </p> * <p> * N.B. each matcher in the specified collection will only be used once during a given * examination, so be careful when specifying matchers that may be satisfied by more than * one entry in an examined array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined array */ public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(java.util.Collection<org.hamcrest.Matcher<? super E>> itemMatchers) { return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); }
/** * <p>Creates an order agnostic matcher for arrays that matches when each item in the * examined array is logically equal to one item anywhere in the specified items. * For a positive match, the examined array must be of the same length as the number of * specified items. * </p> * <p>N.B. each of the specified items will only be used once during a given examination, so be * careful when specifying items that may be equal to more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder("bar", "foo"))</pre> * * @param items * the items that must equal the entries of an examined array, in any order */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(E... items) { return ArrayMatching.arrayContainingInAnyOrder(items); }
/** * <p> * Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified matchers. * For a positive match, the examined array must be of the same length as the number of * specified matchers. * </p> * <p> * N.B. each of the specified matchers will only be used once during a given examination, so be * careful when specifying matchers that may be satisfied by more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by an entry in an examined array */ @SafeVarargs public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcrest.Matcher<? super E>... itemMatchers) { return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); }
/** * <p> * Creates an order agnostic matcher for arrays that matches when each item in the * examined array satisfies one matcher anywhere in the specified matchers. * For a positive match, the examined array must be of the same length as the number of * specified matchers. * </p> * <p> * N.B. each of the specified matchers will only be used once during a given examination, so be * careful when specifying matchers that may be satisfied by more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))</pre> * * @param itemMatchers * a list of matchers, each of which must be satisfied by an entry in an examined array */ @SafeVarargs public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) { return arrayContainingInAnyOrder(asList(itemMatchers)); }
/** * <p>Creates an order agnostic matcher for arrays that matches when each item in the * examined array is logically equal to one item anywhere in the specified items. * For a positive match, the examined array must be of the same length as the number of * specified items. * </p> * <p>N.B. each of the specified items will only be used once during a given examination, so be * careful when specifying items that may be equal to more than one entry in an examined * array. * </p> * <p> * For example: * </p> * <pre>assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))</pre> * * @param items * the items that must equal the entries of an examined array, in any order */ @SafeVarargs public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) { return arrayContainingInAnyOrder(asEqualMatchers(items)); }