I am testing my Java code using EasyMock.
The piece of code that I want to mock looks like this:
requestInfo = mupClient.newEnqueueRequestCall().call(requestArgs);
The way I am mocking this is:
expect(mupClient.newEnqueueRequestCall()).andReturn(enqueueRequestCall);
final Capture<EnqueueRequestArgs> captureRequestArgs =
new Capture<EnqueueRequestArgs>();
expect(mupClient.newEnqueueRequestCall().call(capture(captureRequestArgs))).
andThrow(new MUPCoralException("an exception"));
But requestInfo is always null. Even if I change the .andThrow() part to .andReturn(new RequestInfo()), it is still null.
I checked the other similar post but that did not work. Now was I able to comment on it and hence creating a new question.
ANSWER:
add all mock’d objects in replay! Example replay(mockObj1, mockObj2, ...)
Try this:
The problem is that your
enqueRequestCallshould returnrequestInfo.mupClientwill returnenqueueRequestCallonly after you callreplaymethod from easymock.