in future/src/main/java/com/spotify/hamcrest/future/ExceptionallyCompletedFuture.java [43:74]
protected boolean matchesSafely(final Future<T> future, final Description mismatchDescription) {
if (future.isDone()) {
if (future.isCancelled()) {
mismatchDescription.appendText("a future that was cancelled");
return false;
} else {
final T value;
try {
value = future.get();
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (matcher.matches(cause)) {
return true;
} else {
mismatchDescription.appendText("a future completed exceptionally with ");
matcher.describeMismatch(cause, mismatchDescription);
return false;
}
} catch (InterruptedException e) {
throw new AssertionError("This should never happen because the future is completed.");
}
mismatchDescription
.appendText("a future that completed to a value that was ")
.appendValue(value);
return false;
}
} else {
mismatchDescription.appendText("a future that was not done");
return false;
}
}