@Test
public void testDoWithTokenFailedAccessToken() {

    Throwable expException = new IOException("Cannot obtain access token");
    RuntimeException otherException = new RuntimeException("Function failed");
    Function<AccessToken, CompletableFuture<Object>> func = token -> {
        throw otherException;
    };
    CompletableFuture<String> tokenFuture = new CompletableFuture<>();
    tokenFuture.completeExceptionally(expException);
    expectTokenRequest(tokenFuture);
    try {
        tokenProvider.doWithToken(func).join();
        fail("No exception thrown!");
    } catch (CompletionException ex) {
        assertThat(ex.getCause()).isEqualTo(expException);
    }
}