private void awaitAndAssertCancelled(KafkaFuture<?> future, String expectedMessage) {
        CancellationException cancellationException = assertThrows(CancellationException.class, () -> future.get(5, TimeUnit.MINUTES));
        assertEquals(expectedMessage, cancellationException.getMessage());
        assertEquals(CancellationException.class, cancellationException.getClass());

        cancellationException = assertThrows(CancellationException.class, future::get);
        assertEquals(expectedMessage, cancellationException.getMessage());
        assertEquals(CancellationException.class, cancellationException.getClass());

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