|
| 1 | +package org.hamcrest.core; |
| 2 | + |
| 3 | +import org.hamcrest.Description; |
| 4 | +import org.hamcrest.Matcher; |
| 5 | +import org.hamcrest.TypeSafeDiagnosingMatcher; |
| 6 | + |
| 7 | +/** |
| 8 | + * @deprecated As of release 2.1, replaced by {@link IsIterableContaining}. |
| 9 | + */ |
| 10 | +@Deprecated |
| 11 | +public class IsCollectionContaining<T> extends TypeSafeDiagnosingMatcher<Iterable<? super T>> { |
| 12 | + private final IsIterableContaining<T> delegate; |
| 13 | + |
| 14 | + public IsCollectionContaining(Matcher<? super T> elementMatcher) { |
| 15 | + this.delegate = new IsIterableContaining<>(elementMatcher); |
| 16 | + } |
| 17 | + |
| 18 | + @Override |
| 19 | + protected boolean matchesSafely(Iterable<? super T> collection, Description mismatchDescription) { |
| 20 | + return delegate.matchesSafely(collection, mismatchDescription); |
| 21 | + } |
| 22 | + |
| 23 | + @Override |
| 24 | + public void describeTo(Description description) { |
| 25 | + delegate.describeTo(description); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + /** |
| 30 | + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the |
| 31 | + * examined {@link Iterable} yields at least one item that is matched by the specified |
| 32 | + * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable} |
| 33 | + * will stop as soon as a matching item is found. |
| 34 | + * For example: |
| 35 | + * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre> |
| 36 | + * |
| 37 | + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItem(Matcher)}. |
| 38 | + * |
| 39 | + * @param itemMatcher |
| 40 | + * the matcher to apply to items provided by the examined {@link Iterable} |
| 41 | + */ |
| 42 | + public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher) { |
| 43 | + return IsIterableContaining.hasItem(itemMatcher); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the |
| 48 | + * examined {@link Iterable} yields at least one item that is equal to the specified |
| 49 | + * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable} |
| 50 | + * will stop as soon as a matching item is found. |
| 51 | + * For example: |
| 52 | + * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre> |
| 53 | + * |
| 54 | + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItem(Object)}. |
| 55 | + * |
| 56 | + * @param item |
| 57 | + * the item to compare against the items provided by the examined {@link Iterable} |
| 58 | + */ |
| 59 | + public static <T> Matcher<Iterable<? super T>> hasItem(T item) { |
| 60 | + // Doesn't forward to hasItem() method so compiler can sort out generics. |
| 61 | + return IsIterableContaining.hasItem(item); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the |
| 66 | + * examined {@link Iterable} yield at least one item that is matched by the corresponding |
| 67 | + * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of |
| 68 | + * the examined {@link Iterable} will stop as soon as a matching item is found. |
| 69 | + * For example: |
| 70 | + * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre> |
| 71 | + * |
| 72 | + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Matcher[])}}. |
| 73 | + * |
| 74 | + * @param itemMatchers |
| 75 | + * the matchers to apply to items provided by the examined {@link Iterable} |
| 76 | + */ |
| 77 | + @SafeVarargs |
| 78 | + public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) { |
| 79 | + return IsIterableContaining.hasItems(itemMatchers); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the |
| 84 | + * examined {@link Iterable} yield at least one item that is equal to the corresponding |
| 85 | + * item from the specified <code>items</code>. Whilst matching, each traversal of the |
| 86 | + * examined {@link Iterable} will stop as soon as a matching item is found. |
| 87 | + * For example: |
| 88 | + * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> |
| 89 | + * |
| 90 | + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Object[])}}. |
| 91 | + * |
| 92 | + * @param items |
| 93 | + * the items to compare against the items provided by the examined {@link Iterable} |
| 94 | + */ |
| 95 | + @SafeVarargs |
| 96 | + public static <T> Matcher<Iterable<T>> hasItems(T... items) { |
| 97 | + return IsIterableContaining.hasItems(items); |
| 98 | + } |
| 99 | + |
| 100 | +} |
0 commit comments