All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.matchers.JUnitMatchers Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package org.junit.matchers;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matcher;
import org.hamcrest.core.CombinableMatcher.CombinableBothMatcher;
import org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher;
import org.junit.internal.matchers.StacktracePrintingMatcher;

/**
 * Convenience import class: these are useful matchers for use with the assertThat method, but they are
 * not currently included in the basic CoreMatchers class from hamcrest.
 *
 * @since 4.4
 */
public class JUnitMatchers {
    /**
     * @return A matcher matching any collection containing element
     * @deprecated Please use {@link CoreMatchers#hasItem(Object)} instead.
     */
    @Deprecated
    public static  Matcher> hasItem(T element) {
        return CoreMatchers.hasItem(element);
    }

    /**
     * @return A matcher matching any collection containing an element matching elementMatcher
     * @deprecated Please use {@link CoreMatchers#hasItem(Matcher)} instead.
     */
    @Deprecated
    public static  Matcher> hasItem(Matcher elementMatcher) {
        return CoreMatchers.hasItem(elementMatcher);
    }

    /**
     * @return A matcher matching any collection containing every element in elements
     * @deprecated Please use {@link CoreMatchers#hasItems(Object...)} instead.
     */
    @Deprecated
    public static  Matcher> hasItems(T... elements) {
        return CoreMatchers.hasItems(elements);
    }

    /**
     * @return A matcher matching any collection containing at least one element that matches
     *         each matcher in elementMatcher (this may be one element matching all matchers,
     *         or different elements matching each matcher)
     * @deprecated Please use {@link CoreMatchers#hasItems(Matcher...)} instead.
     */
    @Deprecated
    public static  Matcher> hasItems(Matcher... elementMatchers) {
        return CoreMatchers.hasItems(elementMatchers);
    }

    /**
     * @return A matcher matching any collection in which every element matches elementMatcher
     * @deprecated Please use {@link CoreMatchers#everyItem(Matcher)} instead.
     */
    @Deprecated
    public static  Matcher> everyItem(final Matcher elementMatcher) {
        return CoreMatchers.everyItem(elementMatcher);
    }

    /**
     * @return a matcher matching any string that contains substring
     * @deprecated Please use {@link CoreMatchers#containsString(String)} instead.
     */
    @Deprecated
    public static Matcher containsString(java.lang.String substring) {
        return CoreMatchers.containsString(substring);
    }

    /**
     * This is useful for fluently combining matchers that must both pass.  For example:
     * 
     *   assertThat(string, both(containsString("a")).and(containsString("b")));
     * 
* * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static CombinableBothMatcher both(Matcher matcher) { return CoreMatchers.both(matcher); } /** * This is useful for fluently combining matchers where either may pass, for example: *
     *   assertThat(string, either(containsString("a")).or(containsString("b")));
     * 
* * @deprecated Please use {@link CoreMatchers#either(Matcher)} instead. */ @Deprecated public static CombinableEitherMatcher either(Matcher matcher) { return CoreMatchers.either(matcher); } /** * @return A matcher that delegates to throwableMatcher and in addition * appends the stacktrace of the actual Throwable in case of a mismatch. */ public static Matcher isThrowable(Matcher throwableMatcher) { return StacktracePrintingMatcher.isThrowable(throwableMatcher); } /** * @return A matcher that delegates to exceptionMatcher and in addition * appends the stacktrace of the actual Exception in case of a mismatch. */ public static Matcher isException(Matcher exceptionMatcher) { return StacktracePrintingMatcher.isException(exceptionMatcher); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy