@Tested(要被注入的对象也是测试对象)
private ImportHintValidationServiceImpl importHintValidationServiceImpl;
@Injectable(向测试对象注入)
private TradeClient tradeClient;
@Injectable
private IUserInfoHelper iUserInfoHelper;
/**
* Test method for
* {@link com.baidu.rigel.ipangu.hint.entrance.impl.ImportHintValidationServiceImpl#validateHints(com.baidu.rigel.ipangu.hint.entrance.vo.HintLogVo, java.util.List, java.lang.Long)}
* .
*/
@Test
public void testValidateHints() {
new MockUp<IUserInfoHelper>() {
@Mock(静态方法注入)
public Long getUnitPosId() {
return 56665L;
}
};
new NonStrictExpectations() {(录制被注入对象返回)
{
tradeClient.getAllLevel1Ids(anyLong);
List<Long> abc = new ArrayList<Long>();
abc.add(1L);
abc.add(2L);
result = abc;
tradeClient.getAllLevel2(2L);
result = null;
}
};
hintInfo1.setSrcType("1");
hintInfo1.setCustomerType((byte) 0);
hintInfo1.setSiteType((byte) 1);
HintIntentionVo intention1 = new HintIntentionVo();
intention1.setHintIntentionDegree(3L);
List<HintIntentionVo> intentionList = new ArrayList<HintIntentionVo>();
intentionList.add(intention1);
hintInfo1.setIntentionList(intentionList);
List<HintInfo> hintInfoList = new ArrayList<HintInfo>();
hintInfoList.add(hintInfo1);
importHintValidationServiceImpl.validateHints(hintLog, hintInfoList, 1L);(用被注入对象调用对应测试方法)
//加入断言