I am new to JMockit. I am trying to mock a class's method but the property are null. Examples below:
WebServiceUtility:
@Component
public class WebserviceUtility {
public SamResponse getSamResponse(Parameters myParam) {
return callWebService.postCall(myParam);;
}
}
Service Class:
@Autowired
private WebserviceUtility webServiceUtility;
public void checkResponse() {
MyParam myParam = new MyParam();
SamResponse samResponse = WebserviceUtility.getSamResponse(myParam);
if (samResponse.getGoodResponse != null) {
//Do things here
}
}
SamResponse class
public class SamResponse() {
private GoodResponse goodResponse;
private String error;
//setters and getters here..
}
JMockit class:
public void testSamResponseGood() {
final SamResponse samResponse = new SamResponse();
GoodResponse res = new GoodResponse();
samResponse.setGoodResponse(res);
MyParam param = new MyParam();
param.setAtt("test");
new Expectations() {{
webServiceUtility.getSamResponse(param);
result = samResponse ;
times = 1;
}};
}
When I try to check the value of the samResponse, the attributes - error and goodResponse are both null,even I passed the values in the new Expectations(){{}}; How can I return the actual object? What am I missing? Hope someone can give me some light. Thanks in advance.