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.
方法摘要 |
static
<T> org.junit.internal.matchers.CombinableMatcher<T> |
both(org.hamcrest.Matcher<T> matcher)
This is useful for fluently combining matchers that must both pass. |
static org.hamcrest.Matcher<String> |
containsString(String substring)
|
static
<T> org.junit.internal.matchers.CombinableMatcher<T> |
either(org.hamcrest.Matcher<T> matcher)
This is useful for fluently combining matchers where either may pass, for example: |
static
<T> org.hamcrest.Matcher<Iterable<T>> |
everyItem(org.hamcrest.Matcher<T> elementMatcher)
|
static
<T> org.hamcrest.Matcher<Iterable<T>> |
hasItem(org.hamcrest.Matcher<? extends T> elementMatcher)
|
static
<T> org.hamcrest.Matcher<Iterable<T>> |
hasItem(T element)
|
static
<T> org.hamcrest.Matcher<Iterable<T>> |
hasItems(org.hamcrest.Matcher<? extends T>... elementMatchers)
|
static
<T> org.hamcrest.Matcher<Iterable<T>> |
hasItems(T... elements)
|
类方法继承: java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JUnitMatchers
public JUnitMatchers()
hasItem
public static <T> org.hamcrest.Matcher<Iterable<T>> hasItem(T element)
- 参数:
element
-
- 返回:
- A matcher matching any collection containing element
hasItem
public static <T> org.hamcrest.Matcher<Iterable<T>> hasItem(org.hamcrest.Matcher<? extends T> elementMatcher)
- 参数:
elementMatcher
-
- 返回:
- A matcher matching any collection containing an element matching elementMatcher
hasItems
public static <T> org.hamcrest.Matcher<Iterable<T>> hasItems(T... elements)
- 参数:
elements
-
- 返回:
- A matcher matching any collection containing every element in elements
hasItems
public static <T> org.hamcrest.Matcher<Iterable<T>> hasItems(org.hamcrest.Matcher<? extends T>... elementMatchers)
- 参数:
elementMatchers
-
- 返回:
- 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> org.hamcrest.Matcher<Iterable<T>> everyItem(org.hamcrest.Matcher<T> elementMatcher)
- 参数:
elementMatcher
-
- 返回:
- A matcher matching any collection in which every element matches elementMatcher
containsString
public static org.hamcrest.Matcher<String> containsString(String substring)
- 参数:
substring
-
- 返回:
- a matcher matching any string that contains substring
both
public static <T> org.junit.internal.matchers.CombinableMatcher<T> both(org.hamcrest.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(org.hamcrest.Matcher<T> matcher)
- This is useful for fluently combining matchers where either may pass, for example:
assertThat(string, both(containsString("a")).and(containsString("b")));