diff --git a/hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java b/hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java index 385cf999..5a57f50a 100644 --- a/hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java +++ b/hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java @@ -51,4 +51,18 @@ public final void describeTo(Description description) { description.appendText(featureDescription).appendText(" ") .appendDescriptionOf(subMatcher); } + + public static FeatureMatcher ofFunction(final Mapper mapper, Matcher matcher, String featureDescription, String featureName) { + return new FeatureMatcher(matcher, featureDescription, featureName) { + @Override + protected U featureValueOf(T actual) { + return mapper.map(actual); + } + }; + } + + // TODO java 8 @FunctionalInterface + public interface Mapper { + U map(T t); + } }