Last active
August 29, 2015 14:10
-
-
Save dmcg/8ddf275688fd450e977e to your computer and use it in GitHub Desktop.
Hamcrest Matcher transformed by function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TransformingMatcher<U, T> extends TypeSafeMatcher<U> { | |
private final Matcher<T> base; | |
private final Function<? super U, ? extends T> function; | |
public TransformingMatcher(Matcher<T> base, Function<? super U, ? extends T> function) { | |
this.base = base; | |
this.function = function; | |
} | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("transformed version of "); | |
base.describeTo(description); | |
} | |
@Override | |
protected boolean matchesSafely(U item) { | |
return base.matches(function.apply(item)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment