[英]Why will this powermock not work even though it is syntactically correct?
我正在尝试使用能力嘲讽来测试我的课程
这是我的课:
public Basket createBasket(Basket basket) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("In BasketInformationServiceImpl.createBasket : [" + basket.toString() + "]");
}
try {
if (StringUtils.isBlank(basket.getBasketAdditionsAllowedInd())) {
basket.setBasketAdditionsAllowedInd("Y");
}
这是我的测试:
public void testCreateBasketCallsSetBasketAdditionsAllowedIndInBasket(){
PowerMockito.mockStatic(StringUtils.class);
when(StringUtils.isBlank(mockBasket.getBasketAdditionsAllowedInd())).thenReturn(true);
basketInformationServiceImpl.createBasket(mockBasket);
verify(mockBasket,times(1)).setBasketAdditionsAllowedInd(anyString());
}
我得到的错误是:
org.mockito.exceptions.missing.WrongTypeOfReturnValue;
Boolean cannot be returned by getBasketAdditionsAllowedInd()
getBasketAdditionsAllowedInd() should return string
有谁知道我为什么收到此错误以及如何克服它?
ps使用Power Mock作为StringUtils是静态类
您是否在其他地方嘲笑了mockBasket.getBasketAdditionsAllowedInd?
如果是这样,请尝试将有问题的行分为两部分。
String allowedInd = mockBasket.getBasketAdditionsAllowedInd();
when(StringUtils.isBlank(allowedInd)).thenReturn(true);
您为什么仍然嘲笑静态类?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.