Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
Created June 27, 2019 17:54
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 tomwhoiscontrary/a6991ddcbe19b560b265ec97ddf71969 to your computer and use it in GitHub Desktop.
Save tomwhoiscontrary/a6991ddcbe19b560b265ec97ddf71969 to your computer and use it in GitHub Desktop.
The raises matcher
public static Matcher<Callable<?>> raises(Matcher<? super Throwable> sub) {
return new FeatureMatcher<Callable<?>, Throwable>(sub, "thrown exception", "thrown exception") {
@Override
protected Throwable featureValueOf(Callable<?> thing) {
try {
thing.call();
} catch (Throwable e) {
return e;
}
return null;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment