public static CompletableFuture assertThrowsFuture()

in hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Assert.java [54:77]


    public static CompletableFuture<Throwable> assertThrowsFuture(
                                               Class<? extends Throwable> clazz,
                                               ThrowableRunnable runnable) {
        CompletableFuture<Throwable> future = new CompletableFuture<>();
        boolean fail = false;
        try {
            runnable.run();
            fail = true;
        } catch (Throwable e) {
            if (!clazz.isInstance(e)) {
                Assert.fail(String.format(
                            "Bad exception type %s(expected %s)",
                            e.getClass().getName(), clazz.getName()));
            }
            future.complete(e);
        }
        if (fail) {
            String msg = String.format("No exception was thrown(expected %s)",
                                       clazz.getName());
            future.completeExceptionally(new AssertionError(msg));
            Assert.fail(msg);
        }
        return future;
    }