下面代码块里这一段里就是说去调用bandwidthAllocationRuleService.listBandwidthAllocationRule方法的时候直接引用我定义好的ipage,但是我这么写,图一的那个allocationRecords一直是个空,我就很纳闷。然后我排查是什么原因,网上看到一篇博文说是因为对象引用的地址不一致或者参数不一致导致的,但是看着有点懵,有兴趣的可以看一下
https://blog.csdn.net/besto229/article/details/106077901/
我下面这个代码中,
regionId是String类型
resourceGroupId是String类型
bandwidthMock是一个自定义的对象,内部有很多属性
10,1这两个是 long 类型的
Mockito.when(bandwidthAllocationRuleService.listBandwidthAllocationRule(regionId,resourceGroupId,bandwidthMock,10,1)).thenReturn(iPage);
CommonResponse cr = describeBandwidthAllocationRulesAction.processRequest();
所以问题就是出在这个自定义的bandwidthMock对象上,我最后的解决方法是,把String的都改成Mockito.eq(),对象的直接用Mockito.any(XXX.class),
基本数据类型的,直接用Mockito.anyLong()这种,就可以解决了
Mockito.when(bandwidthAllocationRuleService.listBandwidthAllocationRule(Mockito.eq(regionId), Mockito.eq(resourceGroupId)
, Mockito.any(BandwidthAllocationRule.class), Mockito.anyLong(), Mockito.anyLong())).thenReturn(iPage);
CommonResponse cr = describeBandwidthAllocationRulesAction.processRequest();