小编tro*_*erg的帖子

如何模拟 completablefuture.get()?

这是我试图嘲笑的方法:

@VisibleForTesting
public List<Row> processRows2(CompletableFuture future) {
    List<Row> rows2 = new ArrayList<>();
    try {
        DefaultAsyncResultSet beep = (DefaultAsyncResultSet) future.get();
        for (Row b : beep.currentPage()) {
            rows2.add(b);
        }
    }
    catch (ExecutionException | InterruptedException e) {
        LOGGER.error(e);
        LOGGER.error(e.getStackTrace());
        throw new RuntimeException(e.getMessage() + " - Check thread pool resources are enough, may be too many queries in queue");
    }
    return rows2;
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试用它来测试它时(目前只是想让它一直运行到成功或失败):

@Test
public void processRows2test() {
    FeatureDaoImpl gar = new FeatureDaoImpl(connection);
    CompletableFuture L = new CompletableFuture();
    gar.processRows2(L);
}
Run Code Online (Sandbox Code Playgroud)

它无休无止地挂着。我的猜测是 future.get() 是挂在哪里;我不知道。但我不知道如何嘲笑它。我试过这个: …

java unit-testing mocking mockito

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

mocking ×1

mockito ×1

unit-testing ×1