T - The type of the target object which has the feature.U - The type of the feature of the target.public class NamedFeature<T,U> extends Object
FeatureMatcher instances.
Example:
final NamedFeature<File, String> hasName = namedFeature("File", "name", File::getName);
assertThat(new File("path/to/filename"), hasName.thatIs("filename"));
assertThat(new File("path/to/filename"), hasName.that(startsWith("file")));
The failure messages have the form
Expected: File for which name is "filename"
but: name was "othername"
Expected: File for which name a string starting with "file"
but: name was "othername"
| Modifier and Type | Method and Description |
|---|---|
static <T,U> NamedFeature<T,U> |
namedFeature(String targetName,
String featureName,
Function<T,U> extractor)
Create a named feature given descriptive strings and an extractor function.
|
org.hamcrest.Matcher<T> |
that(org.hamcrest.Matcher<? super U> featureValueMatcher)
Obtain a matcher that matches when this feature of the target matches a given matcher.
|
org.hamcrest.Matcher<T> |
thatIs(U featureValue)
Obtain a matcher that matches when this feature of the target is equal to a given value.
|
@Nonnull public static <T,U> NamedFeature<T,U> namedFeature(@Nonnull String targetName, @Nonnull String featureName, @Nonnull Function<T,U> extractor)
T - The type of the target object which has the feature.U - The type of the feature of the target.targetName - a string name for the matcher target type.featureName - a string name for the feature.extractor - an extractor mapping target values to feature values.@Nonnull public org.hamcrest.Matcher<T> that(@Nonnull org.hamcrest.Matcher<? super U> featureValueMatcher)
featureValueMatcher - a matcher for the values of the feature.Matcher which matches the target object when the feature obtained by this objects extractor
matches the given featureValueMatcher.public org.hamcrest.Matcher<T> thatIs(@Nullable U featureValue)
featureValue - the expected value of the feature, which may be null.Matcher which matches the target object when the feature obtained by this objects extractor
Matchers.is(T) the given featureValue.Copyright © 2017 Atlassian. All rights reserved.