-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Sometimes you might want to reuse an existing expression and a given matcher to combine both to a simple Boolean-Expression. Here is an example how this might look like:
private static class MatcherExpressionCombiningExpression<T> extends AbstractExpression<Boolean> {
private final Expression<? extends T> expression;
private final Matcher<? super T> matcher;
private MatcherExpressionCombiningExpression(final Expression<? extends T> expression, final Matcher<? super T> matcher) {
this.expression = expression;
this.matcher = matcher;
}
@Override
public void describeTo(@Nonnull final Description description) {
description.appendText("expression: ");
description.appendDescriptionOf(expression);
description.appendText(", matcher: ");
description.appendDescriptionOf(matcher);
super.describeTo(description);
}
@Override
public Boolean get() {
return matcher.matches(expression.get());
}
@Factory
public static <T> MatcherExpressionCombiningExpression<T> combiningExpression(final Expression<? extends T> expression, final Matcher<? super T> matcher) {
return new MatcherExpressionCombiningExpression<T>(expression, matcher);
}
}Reactions are currently unavailable