public class GeneralMatchers extends Object
| Constructor and Description |
|---|
GeneralMatchers() |
| Modifier and Type | Method and Description |
|---|---|
static org.hamcrest.Matcher<String> |
containsAllStrings(String... substrings)
Obtain a
Matcher<String> which matches if every one of a given strings appears as a substring
of the provided string. |
static <T> org.hamcrest.Matcher<Iterable<T>> |
everyItemIs(org.hamcrest.Matcher<? super T> matcher)
This method is exactly equivalent to
Matchers.everyItem(Matcher) except for its generic
signature; everyItem takes a Matcher<T>, whereas this method takes a
Matcher<? super T>. |
static <T,U extends T> |
matchAs(Class<T> fromClass,
Class<U> matchAsClass,
org.hamcrest.Matcher<? super U> matcher)
Asserts that the target object, declared as
fromClass, is also an instance of matchClass;
then casts it to matchClass and asserts the specified matcher. |
static org.hamcrest.Matcher<String> |
orderedSubstrings(String... substrings)
Obtain a
Matcher<String> which matches if every one of a given strings appears as a substring
of the provided strings and they occur in the same order as they are listed here. |
static <T> org.hamcrest.Matcher<Iterable<T>> |
startsWithItems(Iterable<org.hamcrest.Matcher<? super T>> matchers) |
static <T> org.hamcrest.Matcher<Iterable<T>> |
startsWithItems(org.hamcrest.Matcher<? super T>... ms) |
static <T> org.hamcrest.Matcher<Iterable<T>> |
startsWithItems(org.hamcrest.Matcher<? super T> m1,
org.hamcrest.Matcher<? super T> m2) |
static <T> org.hamcrest.Matcher<T> |
testAllOf(org.hamcrest.Matcher<? super T>... matchers)
Same as
Matchers.allOf(Matcher...), but does not short-circuit; all of the matchers will be tested
even if the first one fails. |
static <T> org.hamcrest.Matcher<T> |
testAllOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second)
Same as
Matchers.allOf(Matcher...), but does not short-circuit; all of the matchers will be tested
even if the first one fails. |
static <T> org.hamcrest.Matcher<T> |
testAllOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third)
Same as
Matchers.allOf(Matcher...), but does not short-circuit; all of the matchers will be tested
even if the first one fails. |
static <T> org.hamcrest.Matcher<T> |
testOnlyIf(org.hamcrest.Matcher<? super T> preconditionMatcher,
org.hamcrest.Matcher<? super T> testMatcher)
Applies
testMatcher only if preconditionMatcher succeeds; if preconditionMatcher fails,
ignores the failure and returns success, skipping testMatcher. |
public static org.hamcrest.Matcher<String> containsAllStrings(String... substrings)
Matcher<String> which matches if every one of a given strings appears as a substring
of the provided string.
Note that there are no requirements around the substrings being in a particular order or prohibiting them from overlapping.
substrings - the strings to require as substrings of the matched string.public static org.hamcrest.Matcher<String> orderedSubstrings(String... substrings)
Matcher<String> which matches if every one of a given strings appears as a substring
of the provided strings and they occur in the same order as they are listed here.
Each substring is searched for from the string index immediately after where any previously matched substring ended, so they will not be matched if they are out of order or overlap.
substrings - the strings to require as substrings of the matched string.public static <T> org.hamcrest.Matcher<Iterable<T>> everyItemIs(org.hamcrest.Matcher<? super T> matcher)
Matchers.everyItem(Matcher) except for its generic
signature; everyItem takes a Matcher<T>, whereas this method takes a
Matcher<? super T>. This is consistent with the signature of Matchers.hasItems(Matcher...),
and can be used in some expressions where there's absolutely no way to use everyItem due to the limitations of
Java type inference.matcher - a matcher to apply to every element in a collectionpublic static <T,U extends T> org.hamcrest.Matcher<T> matchAs(Class<T> fromClass, Class<U> matchAsClass, org.hamcrest.Matcher<? super U> matcher)
fromClass, is also an instance of matchClass;
then casts it to matchClass and asserts the specified matcher.public static <T> org.hamcrest.Matcher<Iterable<T>> startsWithItems(Iterable<org.hamcrest.Matcher<? super T>> matchers)
public static <T> org.hamcrest.Matcher<Iterable<T>> startsWithItems(org.hamcrest.Matcher<? super T> m1, org.hamcrest.Matcher<? super T> m2)
public static <T> org.hamcrest.Matcher<Iterable<T>> startsWithItems(org.hamcrest.Matcher<? super T>... ms)
public static <T> org.hamcrest.Matcher<T> testAllOf(org.hamcrest.Matcher<? super T>... matchers)
Matchers.allOf(Matcher...), but does not short-circuit; all of the matchers will be tested
even if the first one fails.public static <T> org.hamcrest.Matcher<T> testAllOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second)
Matchers.allOf(Matcher...), but does not short-circuit; all of the matchers will be tested
even if the first one fails.public static <T> org.hamcrest.Matcher<T> testAllOf(org.hamcrest.Matcher<T> first,
org.hamcrest.Matcher<? super T> second,
org.hamcrest.Matcher<? super T> third)
Matchers.allOf(Matcher...), but does not short-circuit; all of the matchers will be tested
even if the first one fails.public static <T> org.hamcrest.Matcher<T> testOnlyIf(org.hamcrest.Matcher<? super T> preconditionMatcher,
org.hamcrest.Matcher<? super T> testMatcher)
testMatcher only if preconditionMatcher succeeds; if preconditionMatcher fails,
ignores the failure and returns success, skipping testMatcher.Copyright © 2017 Atlassian. All rights reserved.