[Update] rename completableFuture to productDataFuture

This commit is contained in:
@hangga 2023-10-17 18:45:08 +07:00
parent 3f40e66508
commit 223c0bd32f
1 changed files with 9 additions and 9 deletions

View File

@ -160,23 +160,23 @@ class CompletableFutureTimeoutUnitTest {
@Test
void whenorTimeout_thenGetThrow() {
CompletableFuture<String> completableFuture = fetchProductData();
completableFuture.orTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
assertThrows(ExecutionException.class, completableFuture::get);
CompletableFuture<String> productDataFuture = fetchProductData();
productDataFuture.orTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
assertThrows(ExecutionException.class, productDataFuture::get);
}
@Test
void whencompleteOnTimeout_thenReturnValue() throws ExecutionException, InterruptedException {
CompletableFuture<String> completableFuture = fetchProductData();
completableFuture.completeOnTimeout(DEFAULT_PRODUCT, DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
assertEquals(DEFAULT_PRODUCT, completableFuture.get());
CompletableFuture<String> productDataFuture = fetchProductData();
productDataFuture.completeOnTimeout(DEFAULT_PRODUCT, DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
assertEquals(DEFAULT_PRODUCT, productDataFuture.get());
}
@Test
void whencompleteExceptionally_thenGetThrow() {
CompletableFuture<String> completableFuture = fetchProductData();
executorService.schedule(() -> completableFuture
CompletableFuture<String> productDataFuture = fetchProductData();
executorService.schedule(() -> productDataFuture
.completeExceptionally(new TimeoutException("Timeout occurred")), DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
assertThrows(ExecutionException.class, completableFuture::get);
assertThrows(ExecutionException.class, productDataFuture::get);
}
}