public class NamedFunction<A,B> extends Object implements com.google.common.base.Function<A,B>, Function<A,B>
Function with a descriptive name, and allows you to compose it with a Matcher.
Example:
NamedFunction<Dog, Color> dogColor = namedFunction("color", new Function<Dog, Color>() {
public Color apply(Dog input) {
return input.getColor();
}
});
assertThat(myDog, dogColor.is(equalTo(Color.BLACK)));
| Modifier and Type | Method and Description |
|---|---|
B |
apply(A input)
Delegates the input to the wrapped function.
|
String |
getName()
Returns the descriptive name of this function.
|
org.hamcrest.Matcher<A> |
is(B value)
Shortcut for
is(equalTo(value)). |
org.hamcrest.Matcher<A> |
is(org.hamcrest.Matcher<? super B> matcher)
Returns a
Matcher that passes its target through the wrapped function and then
delegates to another matcher. |
static <A,B> NamedFunction<A,B> |
namedFunction(String name,
Function<A,B> function) |
static <A,B> NamedFunction<A,B> |
namedFunction(String name,
com.google.common.base.Function<A,B> function) |
Function<B,org.hamcrest.Matcher<? super A>> |
valueToEqualMatcher()
Provides a function that produces an
is(equalTo(value)) matcher derived from the wrapped
function, for any given value. |
public static <A,B> NamedFunction<A,B> namedFunction(String name, Function<A,B> function)
public static <A,B> NamedFunction<A,B> namedFunction(String name, com.google.common.base.Function<A,B> function)
public String getName()
public org.hamcrest.Matcher<A> is(org.hamcrest.Matcher<? super B> matcher)
Matcher that passes its target through the wrapped function and then
delegates to another matcher. The name of this function will be used as the description.public Function<B,org.hamcrest.Matcher<? super A>> valueToEqualMatcher()
is(equalTo(value)) matcher derived from the wrapped
function, for any given value. If you have a list of Ts and a NamedFunction<T, U> F},
you can use transform(list, F.valueToEqualMatcher()) to produce { F.is(value1), F.is(value2), ... }.Copyright © 2017 Atlassian. All rights reserved.