【发布时间】:2021-10-29 13:26:28
【问题描述】:
对于这个之前尚未回答的问题,我们深表歉意。但到目前为止,我还没有解决我的问题。 好吧,假设我有一个下面的类,我想测试方法 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) 有人可以告诉我如何解决这个问题吗?
【问题讨论】:
-
我遇到的问题是我的测试中抛出的异常。看看我的帖子
标签: java spring unit-testing