private Throwable awaitAndAssertFailure(KafkaFuture<?> future,
                                            Class<? extends Throwable> expectedException,
                                            String expectedMessage) {
        ExecutionException executionException = assertThrows(ExecutionException.class, () -> future.get(5, TimeUnit.MINUTES));
        assertEquals(expectedException, executionException.getCause().getClass());
        assertEquals(expectedMessage, executionException.getCause().getMessage());

        executionException = assertThrows(ExecutionException.class, future::get);
        assertEquals(expectedException, executionException.getCause().getClass());
        assertEquals(expectedMessage, executionException.getCause().getMessage());

        executionException = assertThrows(ExecutionException.class, () -> future.getNow(null));
        assertEquals(expectedException, executionException.getCause().getClass());
        assertEquals(expectedMessage, executionException.getCause().getMessage());
        return executionException.getCause();
    }
Asserts that the given future is done, didn't fail and was cancelled.
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java