From 0726c6c91f0414e457eb77862e90bbcc2b1bc35f Mon Sep 17 00:00:00 2001 From: Marnes Date: Wed, 16 May 2018 20:25:01 +0200 Subject: [PATCH] FeatureMatcher factory method for java 8 users --- .../src/main/java/org/hamcrest/FeatureMatcher.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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); + } }