0
我嘗試使用功率嘲諷來測試我的課即使它在語法上正確,爲什麼這個powermock不起作用?
這是我的課:
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
沒有人知道爲什麼我得到這個錯誤以及如何結束來吧?
p.s.使用功能模擬爲StringUtils是一個靜態類