我正在尝试模拟下面的私有方法。但是,在第4行,JUnit正在调用相关的validateLanguage方法,并且由于私有方法validateLanguage抛出异常而没有返回模拟值,因为它调用了另一个方法。我的理解是使用PowerMock的JUnit应该跳过对validateLanguage的实际实现的调用。有人可以澄清吗?
public void validateCAR_SourceValidation_Success() throws Exception{
1. long partyId=21;
2. ErrorMessage errorMessage =Mockito.mock(ErrorMessage.class);
CARValidationInfoVO carValidationInfo = Mockito.mock(CARValidationInfoVO.class);
3. BibliographicRecordProcDAO bibRecProcDao=PowerMockito.spy(new BibliographicRecordProcDAO());
4. PowerMockito.doReturn(true).when(bibRecProcDao,"validateLanguage",carValidationInfo,true,errorMessage);
5. bibRecProcDao.validateCARFile(carValidationInfo, partyId);
}
private boolean validateLanguage(CARValidationInfoVO carValidationInfo, boolean successFlag, ErrorMessage errorMessage) throws OPSBankServiceDAOException {
boolean tempFlag;
boolean tmpFlag = successFlag;
if (Utility.isNotEmpty(carValidationInfo.getLanguageList())
&& carValidationInfo.getLanguageList().iterator().hasNext()) {
tempFlag = validateLanguages(carValidationInfo.getLanguageList(),
errorMessage);
tmpFlag = tmpFlag && tempFlag;
}
return tmpFlag;
}
答案 0 :(得分:0)
你确定你的方法调用被嘲笑了吗?您期望的CARValidationInfoVO对象是否等于将对象传递给实际方法调用?