JUnitMatchers (JUnit API)
Keywords: org.junit.matchers.JUnitMatchers class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.junit.matchers
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.

Constructor Summary
`JUnitMatchers()`

Method Summary
`static
`<T> org.junit.internal.matchers.CombinableMatcher<T>`
` | `both(Matcher<T> matcher)` This is useful for fluently combining matchers that must both pass.
`static Matcher<String>` | `containsString(String substring)`
`static
`<T> org.junit.internal.matchers.CombinableMatcher<T>`
` | `either(Matcher<T> matcher)` This is useful for fluently combining matchers where either may pass, for example:
`static
`<T> Matcher<Iterable<T>>`
` | `everyItem(Matcher<T> elementMatcher)`
`static
`<T> Matcher<Iterable<T>>`
` | `hasItem(Matcher<? extends T> elementMatcher)`
`static
`<T> Matcher<Iterable<T>>`
` | `hasItem(T element)`
`static
`<T> Matcher<Iterable<T>>`
` | `hasItems(Matcher<? extends T>... elementMatchers)`
`static
`<T> Matcher<Iterable<T>>`
` | `hasItems(T... elements)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JUnitMatchers

    public JUnitMatchers()

Method Detail

### hasItem

    public static <T> Matcher<Iterable<T>> hasItem(T element)

  Parameters:
    `element` -
  Returns:
    A matcher matching any collection containing element

### hasItem

    public static <T> Matcher<Iterable<T>> hasItem(Matcher<? extends T> elementMatcher)

  Parameters:
    `elementMatcher` -
  Returns:
    A matcher matching any collection containing an element matching elementMatcher

### hasItems

    public static <T> Matcher<Iterable<T>> hasItems(T... elements)

  Parameters:
    `elements` -
  Returns:
    A matcher matching any collection containing every element in elements

### hasItems

    public static <T> Matcher<Iterable<T>> hasItems(Matcher<? extends T>... elementMatchers)

  Parameters:
    `elementMatchers` -
  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

    public static <T> Matcher<Iterable<T>> everyItem(Matcher<T> elementMatcher)

  Parameters:
    `elementMatcher` -
  Returns:
    A matcher matching any collection in which every element matches elementMatcher

### containsString

    public static Matcher<String> containsString(String substring)

  Parameters:
    `substring` -
  Returns:
    a matcher matching any string that contains substring

### both

    public static <T> org.junit.internal.matchers.CombinableMatcher<T> both(Matcher<T> matcher)

  This is useful for fluently combining matchers that must both pass. For example:

         assertThat(string, both(containsString("a")).and(containsString("b")));

### either

    public static <T> org.junit.internal.matchers.CombinableMatcher<T> either(Matcher<T> matcher)

  This is useful for fluently combining matchers where either may pass, for example:

         assertThat(string, both(containsString("a")).and(containsString("b")));

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD