1 回答

TA貢獻1776條經(jīng)驗 獲得超12個贊
我能夠通過下面的代碼解決我的問題。在參數(shù)中使用 withInstanceOf(clazz) 并提供實際對象(在新的 Expectataions 之上)返回實際對象。我的舊代碼是,我正在傳遞 MyParam.class 的實際實例,然后它按預(yù)期返回 goodResponse 對象。
舊代碼:
MyParam params = new MyParams();
param.setAtt("test");
new Expectations() {{
webServiceUtility.getSamResponse(params);
result = samResponse ;
times = 1;
}};
固定代碼:
public void testSamResponseGood() {
final SamResponse samResponse = new SamResponse();
GoodResponse res = new GoodResponse();
samResponse.setGoodResponse(res);
new Expectations() {{
webServiceUtility.getSamResponse(withInstanceOf(MyParam.class));
result = samResponse ;
times = 1;
}};
}
希望這對遇到相同問題的其他人有所幫助。
添加回答
舉報