首页 > 解决方案 > 论据不一样!通缉

问题描述

对于这个之前尚未回答的问题,我们深表歉意。但到目前为止,我还没有解决我的问题。好的,假设我在下面有一个类,我想测试方法 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) 有人可以告诉我如何解决这个问题吗?

标签: javaspringunit-testing

解决方案


我解决了我的问题。问题是它通过传递给我的 QueryWrapper 服务注入来更改实现细节,从而正确地模拟这个。


推荐阅读