I'm trying to get to grips with EasyMock to mock some calls to Jersey client APIs... I'm trying to mock a call to the following call Builder API:
<T> T post(Entity<?> entity, Class<T> responseType);
doing the following:
EasyMock.expect(mockInvocationBuilder.post(Entity.json(request), Response.class)).andReturn(mockResponse).anyTimes();
this is giving me the following error:
java.lang.AssertionError:
Unexpected method call Builder.post(Entity{entity=com.ibm.apin.apim.request.CreateOrgRequest@936a7073, variant=Variant[mediaType=application/json, language=null, encoding=null], annotations=[]}, class javax.ws.rs.core.Response):
Can anyone see what I'm doing wrong here and how I can mock this correctly?
See EasyMock User Guide:
To match an actual method call on the Mock Object with an expectation,
Object
arguments are by default compared withequals()
.
You have to override equals()
, use a built-in argument matcher (like EasyMock#anyObject
), write your own IArgumentMatcher
or use a Capture
.