Java Mockito如何将类型传递给返回CompletableFuture的泛型SupplySync方法?

Java Mockito如何将类型传递给返回CompletableFuture的泛型SupplySync方法?,java,concurrency,mocking,mockito,powermock,Java,Concurrency,Mocking,Mockito,Powermock,假设我有一个遗嘱执行人: public class ExecutorUtil { private ExecutorService executorService; public <T> CompletableFuture<T> supplyAsync(Supplier<T> supplier) { return CompletableFuture.supplyAsync(supplier, executorService); } } 公共类执行器u

假设我有一个遗嘱执行人:

public class ExecutorUtil {
private ExecutorService executorService;

public <T> CompletableFuture<T> supplyAsync(Supplier<T> supplier) {
    return CompletableFuture.supplyAsync(supplier, executorService);
}
}
公共类执行器util{
私人遗嘱执行人服务;
公共完整未来供应同步(供应商){
返回CompletableFuture.supplyAsync(供应商、服务);
}
}
以及对通用SupplySync方法的调用,如:

public CompletableFuture<List<String>> getBuryListFuture(){
    CompletableFuture<List<String>> buryFuture = executorUtil.supplyAsync( () -> {
        List<String> burySkus = null;
        try {
            System.out.println("Here bury:");
            burySkus = ruleEngine.getBuriedSkus();
        } catch (Exception e) {
            LOGGER.info("[ERROR]: There is some issue with RuleEngine");
        }
        return burySkus;
    });
    return buryFuture;
}
public CompletableFuture getBuryListFuture(){
CompletableFuture buryFuture=executorUtil.SupplySync(()->{
列表burySkus=null;
试一试{
System.out.println(“Here bury:”);
burySkus=ruleEngine.getBuriedSkus();
}捕获(例外e){
LOGGER.info(“[错误]:RuleEngine存在一些问题”);
}
返回布里斯库斯;
});
返回埋葬未来;
}
以及:

public CompletableFuture getStrategyListFuture(源代码){
CompletableFuture strategyFuture=executorUtil.SupplySync(()->{
列表策略列表;
试一试{
strategyList=recommendationService.execute(source.getStrategies();
策略列表=移除的副本(策略列表);
}捕获(OrchestrationException e){
抛出新的CompletionException(e);
}
返回策略列表;
});
回归战略未来;
}
如何让mockito模拟executor对每个调用的不同响应?到目前为止,我只能嘲笑两人的相同反应

使用:

CompletableFuture<Object> future3 = new CompletableFuture<>();
future3.complete(recResponse.getStrategies());
PowerMockito.when(executorUtil.supplyAsync(Matchers.any())).thenReturn(future3);
completablefuture3=新的CompletableFuture();
未来3.完成(response.getStrategies());
PowerMockito.when(executorUtil.supplyAsync(Matchers.any())。然后返回(future3);
尝试与以下方面进行区分:

PowerMockito.when(executorUtil.supplyAsync(Matchers.<Supplier<List<String>>>any())).thenReturn(future4);
    PowerMockito.when(executorUtil.supplyAsync(Matchers.<Supplier<List<StrategyDTO>>>any())).thenReturn(future3);
PowerMockito.when(executorUtil.supplyAsync(Matchers.any())。然后返回(future4);
PowerMockito.when(executorUtil.supplyAsync(Matchers.any())。然后返回(future3);
但这没什么区别

PowerMockito.when(executorUtil.supplyAsync(Matchers.<Supplier<List<String>>>any())).thenReturn(future4);
    PowerMockito.when(executorUtil.supplyAsync(Matchers.<Supplier<List<StrategyDTO>>>any())).thenReturn(future3);