junit - 关于如何在 Java8 中使用 Mockito forEach 进行 junit 测试的问题
问题描述
我有以下方法,我需要使用 JUNIT 和 Mockito 对其进行单元测试。我很困惑如何测试返回 void 的 foreach 方法。
public List<Data> extractOutPutResponse(List<SearchHit> searchHits) {
List<Data> outputData = new ArrayList<>();
Gson gson = new Gson();
searchHits.forEach(hit -> outputData.add(gson.fromJson(hit.getSourceAsString(), Data.class)));
return outputData;
}