Having the following class:
class ToTest{
@Autowired
private Service service;
public String make(){
//do some calcs
obj.setParam(param);
String inverted = service.execute(obj);
return "<" + inverted.toString() + ">";
}
}
I'd like to add a test that asserts me that service.execute is called with an object with the param X.
I'd do that with a verification. I want to mock this call and make it return something testable. I do that with an expectations.
@Tested
ToTest toTest;
@Injected
Service service;
new NonStrictExpectations(){
{
service.exceute((CertainObject)any)
result = "b";
}
};
toTest.make();
new Verifications(){
{
CertainObject obj;
service.exceute(obj = withCapture())
assertEquals("a",obj.getParam());
}
};
I get a null pointer on obj.getParam(). Apparently the verification does not work. If I remove the expectation it works but then I get a null pointer in inverted.toString().
How would you guys make this work?