java - 论据不一样!通缉
问题描述
对于这个之前尚未回答的问题,我们深表歉意。但到目前为止,我还没有解决我的问题。好的,假设我在下面有一个类,我想测试方法 checkMail():
public class SupplierRosServiceImpl implements SupplierRosService {
@Autowired
private OpeSupplierService supplierService;
@Autowired
private OpeSupplierMapper opeSupplierMapper;
@Autowired
private OpeSupplierTraceService supplierTraceService;
private SupplierServiceMapper supplierServiceMapper;
@DubboReference
private IdAppService idAppService;
@Override
public Map<String, Integer> countStatus(GeneralEnter enter) {
List<CountByStatusResult> statusResults = supplierServiceMapper.countStatus(enter);
Map<String, Integer> map = new HashMap<>();
for (CountByStatusResult item : statusResults) {
map.put(item.getStatus(), item.getTotalCount());
}
for (SupplierStatusEnum status : SupplierStatusEnum.values()) {
if (!map.containsKey(status.getValue())) {
map.put(status.getValue(), 0);
}
}
return map;
}
public Boolean checkMail(String mail,String idStr) {
QueryWrapper<OpeSupplier> wrapper = new QueryWrapper<>();
wrapper.eq(OpeSupplier.COL_CONTACT_EMAIL, mail);
wrapper.eq(OpeSupplier.COL_DR, 0);
if(!Strings.isNullOrEmpty(idStr)){
wrapper.ne(OpeSupplier.COL_ID, Long.parseLong(idStr));
}
return opeSupplierMapper.selectCount(wrapper) > 0 ? Boolean.FALSE : Boolean.TRUE;
}
在我的测试课上,我有:
class SupplierRosServiceImplTest {
@InjectMocks
SupplierRosServiceImpl supplierRosService;
@Mock
QueryWrapper queryWrapper;
@Mock
private OpeSupplierMapper ope;
@Test
void ItShouldCheckMail() {
//when
supplierRosService.checkMail("myEmailAdress", "123456");
//then
verify(ope).selectCount(queryWrapper);
}
异常告诉:参数不同!想要: ope.selectCount(querywrapper) 实际调用有不同的争论: ope.selectCount(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper@ba1f559) 有人可以告诉我如何解决这个问题吗?
解决方案
我解决了我的问题。问题是它通过传递给我的 QueryWrapper 服务注入来更改实现细节,从而正确地模拟这个。
推荐阅读
- electron - 无法删除电子开发中的菜单
- azure-devops - Azure Devops 构建自定义条件 - 以以前的构建为目标
- php - 不使用数据库的 PHP 登录和注册表单问题
- r - 如何使用 dplyr 计算 R 中数据框列中的重复次数?
- visual-studio-code - VS Code 用文件打开扩展主机
- arrays - “TypeError:在 JSON 上循环时无法读取未定义的属性‘名称’”
- linux - 我想在文件 config.xml 中使用 sed 或 awk 命令添加 3 行
- ruby-on-rails - 多态关联轨道的相反方向
- python - 在 Python 中的 Jupyter Notebook 中显示决策树的巨大问题:ExecutableNotFound?
- java - sc.hasNextLine() 的无限循环