Skip to content

Instantly share code, notes, and snippets.

@josketres
Created June 24, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josketres/2971079d0865010b2834f582f5a443e5 to your computer and use it in GitHub Desktop.
Save josketres/2971079d0865010b2834f582f5a443e5 to your computer and use it in GitHub Desktop.
package com.josketres.test.util;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import java.util.function.Function;
/**
* Utilities and syntactic sugar stuff for hamcrest.
*/
public class CaraHamcrestSugar {
private CaraHamcrestSugar() {
}
/**
* An easier way to create a FeatureMatcher.
*/
public static <T, U> Matcher<T> featureMatcher(Function<T, U> map, String featureName, Matcher<? super U> subMatcher) {
return new FeatureMatcher<T, U>(subMatcher, featureName, featureName) {
@Override
protected U featureValueOf(T o) {
return map.apply(o);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment