@Test public void testDoWithTokenSuccess() { CompletableFuture<String> tokenFuture = CompletableFuture.completedFuture(TOKEN); Function<AccessToken, CompletableFuture<Object>> func = token -> CompletableFuture.completedFuture(token.getToken()); expectTokenRequest(tokenFuture); Object result = tokenProvider.doWithToken(func).join(); assertThat(result).isEqualTo(TOKEN); }
public <T> CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func) { return obtainAccessToken() .thenCompose(token -> func.apply(token) .whenComplete((result, exception) -> onRequestComplete(token, exception))); }
AccessTokenProvider { public <T> CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func) { return obtainAccessToken() .thenCompose(token -> func.apply(token) .whenComplete((result, exception) -> onRequestComplete(token, exception))); } }
AccessTokenProvider { public <T> CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func) { return obtainAccessToken() .thenCompose(token -> func.apply(token) .whenComplete((result, exception) -> onRequestComplete(token, exception))); } AccessTokenProvider(SW360AuthenticationClient authClient); }
AccessTokenProvider { public <T> CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func) { return obtainAccessToken() .thenCompose(token -> func.apply(token) .whenComplete((result, exception) -> onRequestComplete(token, exception))); } AccessTokenProvider(SW360AuthenticationClient authClient); SW360AuthenticationClient getAuthClient(); CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func); }
AccessTokenProvider { public <T> CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func) { return obtainAccessToken() .thenCompose(token -> func.apply(token) .whenComplete((result, exception) -> onRequestComplete(token, exception))); } AccessTokenProvider(SW360AuthenticationClient authClient); SW360AuthenticationClient getAuthClient(); CompletableFuture<T> doWithToken(Function<? super AccessToken, ? extends CompletableFuture<T>> func);  }