|
| 1 | +package org.junit.matchers; |
| 2 | + |
| 3 | +import org.hamcrest.CoreMatchers; |
| 4 | +import org.hamcrest.Matcher; |
| 5 | +import org.hamcrest.collection.MatchIterables; |
| 6 | +import org.hamcrest.core.CombinableMatcher.CombinableBothMatcher; |
| 7 | +import org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher; |
| 8 | + |
| 9 | +/** |
| 10 | + * Transient import class. Copied here from JUnit 4.4 in preparation for removing Hamcrest from |
| 11 | + * JUnit dependencies. |
| 12 | + * |
| 13 | + * @deprecated |
| 14 | + * @since 3.0.0 |
| 15 | + */ |
| 16 | +public class JUnitMatchers { |
| 17 | + /** |
| 18 | + * @return A matcher matching any collection containing element |
| 19 | + * @deprecated Please use {@link MatchIterables#hasItem(Object)} instead. |
| 20 | + */ |
| 21 | + @Deprecated |
| 22 | + public static <T> Matcher<Iterable<? super T>> hasItem(T element) { |
| 23 | + return MatchIterables.hasItem(element); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @return A matcher matching any collection containing an element matching elementMatcher |
| 28 | + * @deprecated Please use {@link MatchIterables#hasItem(Matcher)} instead. |
| 29 | + */ |
| 30 | + @Deprecated |
| 31 | + public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> elementMatcher) { |
| 32 | + return MatchIterables.hasItem(elementMatcher); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @return A matcher matching any collection containing every element in elements |
| 37 | + * @deprecated Please use {@link MatchIterables#hasItems(Object...)} instead. |
| 38 | + */ |
| 39 | + @Deprecated |
| 40 | + public static <T> Matcher<Iterable<T>> hasItems(T... elements) { |
| 41 | + return MatchIterables.hasItems(elements); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @return A matcher matching any collection containing at least one element that matches |
| 46 | + * each matcher in elementMatcher (this may be one element matching all matchers, |
| 47 | + * or different elements matching each matcher) |
| 48 | + * @deprecated Please use {@link MatchIterables#hasItems(Matcher...)} instead. |
| 49 | + */ |
| 50 | + @Deprecated |
| 51 | + public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... elementMatchers) { |
| 52 | + return MatchIterables.hasItems(elementMatchers); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @return A matcher matching any collection in which every element matches elementMatcher |
| 57 | + * @deprecated Please use {@link MatchIterables#everyItem(Matcher)} instead. |
| 58 | + */ |
| 59 | + @Deprecated |
| 60 | + public static <T> Matcher<Iterable<? extends T>> everyItem(final Matcher<T> elementMatcher) { |
| 61 | + return MatchIterables.everyItem(elementMatcher); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @return a matcher matching any string that contains substring |
| 66 | + * @deprecated Please use {@link CoreMatchers#containsString(String)} instead. |
| 67 | + */ |
| 68 | + @Deprecated |
| 69 | + public static Matcher<String> containsString(String substring) { |
| 70 | + return CoreMatchers.containsString(substring); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * This is useful for fluently combining matchers that must both pass. For example: |
| 75 | + * <pre> |
| 76 | + * assertThat(string, both(containsString("a")).and(containsString("b"))); |
| 77 | + * </pre> |
| 78 | + * |
| 79 | + * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. |
| 80 | + */ |
| 81 | + @Deprecated |
| 82 | + public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { |
| 83 | + return CoreMatchers.both(matcher); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * This is useful for fluently combining matchers where either may pass, for example: |
| 88 | + * <pre> |
| 89 | + * assertThat(string, either(containsString("a")).or(containsString("b"))); |
| 90 | + * </pre> |
| 91 | + * |
| 92 | + * @deprecated Please use {@link CoreMatchers#either(Matcher)} instead. |
| 93 | + */ |
| 94 | + @Deprecated |
| 95 | + public static <T> CombinableEitherMatcher<T> either(Matcher<? super T> matcher) { |
| 96 | + return CoreMatchers.either(matcher); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @return A matcher that delegates to throwableMatcher and in addition |
| 101 | + * appends the stacktrace of the actual Throwable in case of a mismatch. |
| 102 | + */ |
| 103 | + public static <T extends Throwable> Matcher<T> isThrowable(Matcher<T> throwableMatcher) { |
| 104 | + return MatchThrowables.isThrowable(throwableMatcher); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @return A matcher that delegates to exceptionMatcher and in addition |
| 109 | + * appends the stacktrace of the actual Exception in case of a mismatch. |
| 110 | + */ |
| 111 | + public static <T extends Exception> Matcher<T> isException(Matcher<T> exceptionMatcher) { |
| 112 | + return MatchThrowables.isException(exceptionMatcher); |
| 113 | + } |
| 114 | +} |
0 commit comments