I'm not massively knowledgeable on REST services, but a web service that starts with get
and returns void seems very odd to me.
That aside, you will need to expect the call to getAllBooks
as your service is a mock.
From the look of it, the fetchAllBooks
method instantiates the MethodCallBack
and then provides it to mock service. So, if you want to make changes to it so that it is in some expected state when the fetchAllBooks
method continues, you could use andAnswer()
from the expectation.
Something like this should do the trick:
MyRestService mService = createNiceMock(MyRestService.class);
mService.getAllBooks(EasyMock.isA(MethodCallcack.class));
EasyMock.expectLastCall().andAnswer(new IAnswer() {
@Override
public Object answer() throws Throwable {
final Object[] currentArguments = EasyMock.getCurrentArguments();
MethodCallback callback = ((MethodCallback)currentArguments[0]);
//Set whatever you need to on your MethodCallback so that the data makes it back.
return null;
}
});
//Don't forget to replay
EasyMock.replay(mService);
There is a good stack overflow post about this sort of thing here too