protected boolean matchesSafely()

in future/src/main/java/com/spotify/hamcrest/future/SuccessfullyCompletedFuture.java [43:72]


  protected boolean matchesSafely(
      final Future<? extends T> future, final Description mismatchDescription) {
    if (future.isDone()) {
      if (future.isCancelled()) {
        mismatchDescription.appendText("a future that was cancelled");
        return false;
      } else {
        try {
          final T item = future.get();
          if (matcher.matches(item)) {
            return true;
          } else {
            mismatchDescription.appendText("a future that completed to a value that ");
            matcher.describeMismatch(item, mismatchDescription);
            return false;
          }
        } catch (InterruptedException e) {
          throw new AssertionError("This should never happen because the future is completed.");
        } catch (ExecutionException e) {
          mismatchDescription
              .appendText("a future that completed exceptionally with ")
              .appendText(Utils.getStackTraceAsString(e.getCause()));
          return false;
        }
      }
    } else {
      mismatchDescription.appendText("a future that was not completed");
      return false;
    }
  }