有人可以帮助为下面的代码部分(尤其是添加回调部分)编写 JUnit 测试吗?我不知道如何使用回调为 Listenablefuture 编写单元测试用例
private void handleResponse(final ListenableFuture<UserRecordResult> response, CompletableFuture future) {
Futures.addCallback(response, new FutureCallback<UserRecordResult>() {
@Override
public void onFailure(@Nonnull Throwable throwable) {
future.completeExceptionally(new Exception("Fail to put record" + throwable.getMessage()));
}
@Override
public void onSuccess(UserRecordResult result) {
if(result.isSuccessful()) {
future.complete(true);
} else {
future.completeExceptionally(new Exception("Fail to put record"));
}
}
});
}
杨__羊羊
相关分类