public final class ComposeMatchers extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> ConjunctionMatcher<T> |
compose(Iterable<org.hamcrest.Matcher<? super T>> matchers)
Returns a matcher that logically ANDs the specified matchers with any number of further matchers.
|
static <T> ConjunctionMatcher<T> |
compose(org.hamcrest.Matcher<? super T>... matchers)
Returns a matcher that logically ANDs the specified matchers with any number of further matchers.
|
static <T> ConjunctionMatcher<T> |
compose(String compositeDescription,
Iterable<org.hamcrest.Matcher<? super T>> matchers)
Returns a matcher that logically ANDs the specified matchers with any number of further matchers.
|
static <T> ConjunctionMatcher<T> |
compose(String compositeDescription,
org.hamcrest.Matcher<? super T>... matchers)
Returns a matcher that logically ANDs the specified matchers with any number of further matchers.
|
static <T,U> org.hamcrest.Matcher<T> |
hasFeature(Function<T,U> featureFunction,
org.hamcrest.Matcher<? super U> featureMatcher)
Returns a matcher that matches the specified feature of an object.
|
static <T,U> org.hamcrest.Matcher<T> |
hasFeature(String featureName,
Function<T,U> featureFunction,
org.hamcrest.Matcher<? super U> featureMatcher)
Returns a matcher that matches the specified feature of an object.
|
static <T,U> org.hamcrest.Matcher<T> |
hasFeature(String featureDescription,
String featureName,
Function<T,U> featureFunction,
org.hamcrest.Matcher<? super U> featureMatcher)
Returns a matcher that matches the specified feature of an object.
|
static <T,U> org.hamcrest.Matcher<T> |
hasFeatureValue(Function<T,U> featureFunction,
U featureValue)
Returns a matcher that matches the specified feature value of an object.
|
static <T,U> org.hamcrest.Matcher<T> |
hasFeatureValue(String featureName,
Function<T,U> featureFunction,
U featureValue)
Returns a matcher that matches the specified feature value of an object.
|
static <T,U> org.hamcrest.Matcher<T> |
hasFeatureValue(String featureDescription,
String featureName,
Function<T,U> featureFunction,
U featureValue)
Returns a matcher that matches the specified feature value of an object.
|
@SafeVarargs public static <T> ConjunctionMatcher<T> compose(org.hamcrest.Matcher<? super T>... matchers)
For example:
assertThat("ham", compose(startsWith("h")).and(containsString("a")).and(endsWith("m")));
See ConjunctionMatcher as to how this matcher differs from allOf and both.T - the type of the object to be matchedmatchers - the initial matchers to composeConjunctionMatcher@SafeVarargs public static <T> ConjunctionMatcher<T> compose(String compositeDescription, org.hamcrest.Matcher<? super T>... matchers)
For example:
assertThat("ham", compose("a word with", startsWith("h")).and(containsString("a")).and(endsWith("m")));
See ConjunctionMatcher as to how this matcher differs from allOf and both.T - the type of the object to be matchedcompositeDescription - a description of this composite used by describeTomatchers - the initial matchers to composeConjunctionMatcherpublic static <T> ConjunctionMatcher<T> compose(Iterable<org.hamcrest.Matcher<? super T>> matchers)
For example:
assertThat("ham", compose(asList(startsWith("h"), containsString("a"))).and(endsWith("m")));
See ConjunctionMatcher as to how this matcher differs from allOf and both.T - the type of the object to be matchedmatchers - the initial matchers to composeConjunctionMatcherpublic static <T> ConjunctionMatcher<T> compose(String compositeDescription, Iterable<org.hamcrest.Matcher<? super T>> matchers)
For example:
assertThat("ham", compose("a word with", asList(startsWith("h"), containsString("a"))).and(endsWith("m")));
See ConjunctionMatcher as to how this matcher differs from allOf and both.T - the type of the object to be matchedcompositeDescription - a description of this composite used by describeTomatchers - the initial matchers to composeConjunctionMatcherpublic static <T,U> org.hamcrest.Matcher<T> hasFeature(Function<T,U> featureFunction, org.hamcrest.Matcher<? super U> featureMatcher)
For example:
assertThat("ham", hasFeature(String::length, equalTo(3)));
T - the type of the object to be matchedU - the type of the feature to be matchedfeatureFunction - a function to extract the feature from the object. The string representation of this function is used
as the feature name for describeTo and describeMismatch.featureMatcher - the matcher to apply to the specified featurepublic static <T,U> org.hamcrest.Matcher<T> hasFeature(String featureName, Function<T,U> featureFunction, org.hamcrest.Matcher<? super U> featureMatcher)
For example:
assertThat("ham", hasFeature("string length", String::length, equalTo(3)));
T - the type of the object to be matchedU - the type of the feature to be matchedfeatureName - the name of this feature used by describeTo and describeMismatchfeatureFunction - a function to extract the feature from the objectfeatureMatcher - the matcher to apply to the specified featurepublic static <T,U> org.hamcrest.Matcher<T> hasFeature(String featureDescription, String featureName, Function<T,U> featureFunction, org.hamcrest.Matcher<? super U> featureMatcher)
For example:
assertThat("ham", hasFeature("a string with length", "string length", String::length, equalTo(3)));
T - the type of the object to be matchedU - the type of the feature to be matchedfeatureDescription - a description of this feature used by describeTofeatureName - the name of this feature used by describeMismatchfeatureFunction - a function to extract the feature from the objectfeatureMatcher - the matcher to apply to the specified featurepublic static <T,U> org.hamcrest.Matcher<T> hasFeatureValue(Function<T,U> featureFunction, U featureValue)
For example:
assertThat("ham", hasFeatureValue(String::length, 3));
This is equivalent to hasFeature(featureFunction, equalTo(featureValue)).
T - the type of the object to be matchedU - the type of the feature to be matchedfeatureFunction - a function to extract the feature from the object. The string representation of this function is used
as the feature name for describeTo and describeMismatch.featureValue - the feature value to matchpublic static <T,U> org.hamcrest.Matcher<T> hasFeatureValue(String featureName, Function<T,U> featureFunction, U featureValue)
For example:
assertThat("ham", hasFeatureValue("string length", String::length, 3));
This is equivalent to hasFeature(featureName, featureFunction, equalTo(featureValue)).
T - the type of the object to be matchedU - the type of the feature to be matchedfeatureName - the name of this feature used by describeTo and describeMismatchfeatureFunction - a function to extract the feature from the objectfeatureValue - the feature value to matchpublic static <T,U> org.hamcrest.Matcher<T> hasFeatureValue(String featureDescription, String featureName, Function<T,U> featureFunction, U featureValue)
For example:
assertThat("ham", hasFeatureValue("a string with length", "string length", String::length, 3));
This is equivalent to hasFeature(featureDescription, featureName, featureFunction,
equalTo(featureValue)).
T - the type of the object to be matchedU - the type of the feature to be matchedfeatureDescription - a description of this feature used by describeTofeatureName - the name of this feature used by describeMismatchfeatureFunction - a function to extract the feature from the objectfeatureValue - the feature value to matchCopyright © 2015–2018. All rights reserved.