/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) { return IsIterableContaining.hasItems(items); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) { return IsIterableContaining.hasItems(items); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Object[])}}. * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> Matcher<Iterable<T>> hasItems(T... items) { return IsIterableContaining.hasItems(items); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> * * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Matcher[])}}. * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); }
@SuppressWarnings("unchecked") @Test public void matchesMultipleItemsInCollection() { final Matcher<Iterable<String>> matcher1 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("list containing all items", matcher1, asList("a", "b", "c")); final Matcher<Iterable<String>> matcher2 = hasItems("a", "b", "c"); assertMatches("list containing all items (without matchers)", matcher2, asList("a", "b", "c")); final Matcher<Iterable<String>> matcher3 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("list containing all items in any order", matcher3, asList("c", "b", "a")); final Matcher<Iterable<String>> matcher4 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("list containing all items plus others", matcher4, asList("e", "c", "b", "a", "d")); final Matcher<Iterable<String>> matcher5 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertDoesNotMatch("not match list unless it contains all items", matcher5, asList("e", "c", "b", "d")); // 'a' missing }
@Test public void reportsMismatchWithAReadableDescriptionForMultipleItems() { final Matcher<Iterable<Integer>> matcher = hasItems(3, 4); assertMismatchDescription("a collection containing <4> mismatches were: [was <1>, was <2>, was <3>]", matcher, asList(1, 2, 3)); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) { return IsIterableContaining.hasItems(items); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) { return IsIterableContaining.hasItems(items); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is matched by the corresponding * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> * * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Matcher[])}}. * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Object[])}}. * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @SafeVarargs public static <T> Matcher<Iterable<T>> hasItems(T... items) { return IsIterableContaining.hasItems(items); }