0
我想嘲笑如下的私有方法。但是,在第4行,JUnit調用相關的validateLanguage方法,並且由於調用其他方法時從private方法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;
}
是的,我確定。 – Dhrubo