Home > OS >  Arguments are different! wanted
Arguments are different! wanted

Time:11-02

sorry for this question which has been yet answered before. But so far, i didn't resolve my issue. Ok let's say i have a class below that i want to test the method 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;
    }

in my test class i have:

    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);
   }

the exception tell : Argument(s) are different! wanted: ope.selectCount(querywrapper) Actual invocations have differents arguements: ope.selectCount(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper@ba1f559) someone could tell me how to solve this one ?

CodePudding user response:

i resolved my issue. the problem was it to change the implementation detail through passing to my service injection of QueryWrapper thus mock properly this one.

CodePudding user response:

Check the imports in both classes for QueryWrapper if, both are from same package or not, seems imported in test class from different package.

if not then please paste your whole code with imports as well.

  • Related