junit - 如何使用when...then模拟层次结构吸气剂
问题描述
我想模拟一行代码
List<Status> Status = xyz.stream().filter(Predicate).collect(Collectors.toList());
我尝试使用模拟
但它在 Mockito 中抛出空指针。如何模拟这一行,使我的列表不为空并返回我通过 thenReturn 传递的内容。
解决方案
您需要模拟链中的每个部分。
Ung mockedUng = Mockito.mock(Ung.class);
when(mockedUng.getFguBeskaeftigelseStatus()).thenReturn(fGUBeskaeftigelsesStatusList);
when(mockforloeb.getUng()).thenReturn(mockedUng);
推荐阅读
- android-studio - 如何在 Play 商店中显示类似的应用程序?
- arrays - 根据行长 (COUNTA) 动态拆分行并转置为二维数组
- elasticsearch - 多查询 match_phrase_prefix elasticsearch
- eclipse - 解决接触点操作时出错
- kubernetes - Kubernetes - 使用自动生成的服务环境变量之一的值设置环境变量
- javascript - 字符串化 JSON 包含不需要的双引号
- tensorflow.js - 如何从图像中获取张量
- elasticsearch - 术语弹性查询未找到字母数字关键字文本的匹配项
- javascript - 给定一个已知大小的 ArrayBuffer,获取十六进制对的字符串
- javascript - 使用表单数据并基于它生成 HTML