Class JUnitMatchers

java.lang.Object
org.junit.matchers.JUnitMatchers

public class JUnitMatchers extends Object
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
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> org.hamcrest.core.CombinableMatcher.CombinableBothMatcher<T>
    both(org.hamcrest.Matcher<? super T> matcher)
    Deprecated.
    Please use CoreMatchers.both(Matcher) instead.
    static org.hamcrest.Matcher<String>
    Deprecated.
    Please use CoreMatchers.containsString(String) instead.
    static <T> org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher<T>
    either(org.hamcrest.Matcher<? super T> matcher)
    Deprecated.
    Please use CoreMatchers.either(Matcher) instead.
    static <T> org.hamcrest.Matcher<Iterable<? extends T>>
    everyItem(org.hamcrest.Matcher<T> elementMatcher)
    Deprecated.
    Please use CoreMatchers.everyItem(Matcher) instead.
    static <T> org.hamcrest.Matcher<Iterable<? super T>>
    hasItem(org.hamcrest.Matcher<? super T> elementMatcher)
    Deprecated.
    Please use CoreMatchers.hasItem(Matcher) instead.
    static <T> org.hamcrest.Matcher<Iterable<? super T>>
    hasItem(T element)
    Deprecated.
    Please use CoreMatchers.hasItem(Object) instead.
    static <T> org.hamcrest.Matcher<Iterable<T>>
    hasItems(org.hamcrest.Matcher<? super T>... elementMatchers)
    Deprecated.
    Please use CoreMatchers.hasItems(Matcher...) instead.
    static <T> org.hamcrest.Matcher<Iterable<T>>
    hasItems(T... elements)
    Deprecated.
    Please use CoreMatchers.hasItems(Object...) instead.
    static <T extends Exception>
    org.hamcrest.Matcher<T>
    isException(org.hamcrest.Matcher<T> exceptionMatcher)
     
    static <T extends Throwable>
    org.hamcrest.Matcher<T>
    isThrowable(org.hamcrest.Matcher<T> throwableMatcher)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JUnitMatchers

      public JUnitMatchers()
  • Method Details

    • hasItem

      @Deprecated public static <T> org.hamcrest.Matcher<Iterable<? super T>> hasItem(T element)
      Deprecated.
      Please use CoreMatchers.hasItem(Object) instead.
      Returns:
      A matcher matching any collection containing element
    • hasItem

      @Deprecated public static <T> org.hamcrest.Matcher<Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> elementMatcher)
      Deprecated.
      Please use CoreMatchers.hasItem(Matcher) instead.
      Returns:
      A matcher matching any collection containing an element matching elementMatcher
    • hasItems

      @Deprecated public static <T> org.hamcrest.Matcher<Iterable<T>> hasItems(T... elements)
      Deprecated.
      Please use CoreMatchers.hasItems(Object...) instead.
      Returns:
      A matcher matching any collection containing every element in elements
    • hasItems

      @Deprecated public static <T> org.hamcrest.Matcher<Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... elementMatchers)
      Deprecated.
      Please use CoreMatchers.hasItems(Matcher...) instead.
      Returns:
      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)
    • everyItem

      @Deprecated public static <T> org.hamcrest.Matcher<Iterable<? extends T>> everyItem(org.hamcrest.Matcher<T> elementMatcher)
      Deprecated.
      Please use CoreMatchers.everyItem(Matcher) instead.
      Returns:
      A matcher matching any collection in which every element matches elementMatcher
    • containsString

      @Deprecated public static org.hamcrest.Matcher<String> containsString(String substring)
      Deprecated.
      Please use CoreMatchers.containsString(String) instead.
      Returns:
      a matcher matching any string that contains substring
    • both

      @Deprecated public static <T> org.hamcrest.core.CombinableMatcher.CombinableBothMatcher<T> both(org.hamcrest.Matcher<? super T> matcher)
      Deprecated.
      Please use CoreMatchers.both(Matcher) instead.
      This is useful for fluently combining matchers that must both pass. For example:
         assertThat(string, both(containsString("a")).and(containsString("b")));
       
    • either

      @Deprecated public static <T> org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher<T> either(org.hamcrest.Matcher<? super T> matcher)
      Deprecated.
      Please use CoreMatchers.either(Matcher) instead.
      This is useful for fluently combining matchers where either may pass, for example:
         assertThat(string, either(containsString("a")).or(containsString("b")));
       
    • isThrowable

      public static <T extends Throwable> org.hamcrest.Matcher<T> isThrowable(org.hamcrest.Matcher<T> throwableMatcher)
      Returns:
      A matcher that delegates to throwableMatcher and in addition appends the stacktrace of the actual Throwable in case of a mismatch.
    • isException

      public static <T extends Exception> org.hamcrest.Matcher<T> isException(org.hamcrest.Matcher<T> exceptionMatcher)
      Returns:
      A matcher that delegates to exceptionMatcher and in addition appends the stacktrace of the actual Exception in case of a mismatch.