小编Yak*_*sev的帖子

如何在 Mockito 中测试使用 ExecutorService 而不使用超时的代码?

我有一堂课。

public class FeedServiceImpl implements FeedService {
    private final Map<FeedType, FeedStrategy> strategyByType;
    private final ExecutorService executorService = Executors.newSingleThreadExecutor(); 

    public FeedServiceImpl(Map<FeedType, FeedStrategy> strategyByType) {
        if (strategyByType.isEmpty()) throw new IllegalArgumentException("strategyByType map is empty");
        this.strategyByType = strategyByType;
    }

    @Override
    public void feed(LocalDate feedDate, FeedType feedType, String uuid) {
        if (!strategyByType.containsKey(feedType)) {
            throw new IllegalArgumentException("Not supported feedType: " + feedType);
        }
        executorService.submit(() -> runFeed(feedType, feedDate, uuid));
    }


    private FeedTaskResult runFeed(FeedType feedType, LocalDate feedDate, String uuid) {
        return strategyByType.get(feedType).feed(feedDate, uuid);
    }
}
Run Code Online (Sandbox Code Playgroud)

如何使用strategyByType.get(feedType).feed(feedDate, uuid) …

java junit unit-testing mockito

4
推荐指数
1
解决办法
6231
查看次数

标签 统计

java ×1

junit ×1

mockito ×1

unit-testing ×1