📅  最后修改于: 2022-03-11 14:56:10.398000             🧑  作者: Mango
@Test
public void completeExceptionallyOnCallbackFailure() {
ListenableFuture failureResponse = Futures.immediateFailedFuture(new RuntimeException());
CompletableFuture future = new CompletableFuture();
handleResponse(failureResponse, future);
assertThat(future.isCompletedExceptionally(), equalTo(true));
}
@Test
public void completeExceptionallyIfUserRecordResultIsNotSuccessful() {
UserRecordResult mockResult = Mockito.mock(UserRecordResult.class);
Mockito.when(mockResult.isSuccessful()).thenReturn(false);
ListenableFuture failureResponse = Futures.immediateFuture(mockResult);
CompletableFuture future = new CompletableFuture();
handleResponse(failureResponse, future);
assertThat(future.isCompletedExceptionally(), equalTo(true));
}
@Test
public void completeSuccessfully() throws ExecutionException, InterruptedException {
UserRecordResult mockResult = Mockito.mock(UserRecordResult.class);
Mockito.when(mockResult.isSuccessful()).thenReturn(true);
ListenableFuture successResponse = Futures.immediateFuture(mockResult);
CompletableFuture future = new CompletableFuture();
handleResponse(successResponse, future);
assertThat(future.get(), equalTo(true));
}