Question

I'm getting frustrated trying to do a simple thing - I want to invoke a method on a mock object and NOT check its return value. I just want to check that it was invoked with the correct parameters.

Example:

MyInterface mockObject = createMock(MyInterface.class);
SomeObject param = new SomeObject();

/* the write object is not void and returns an instance of FooOjbect.
 * I want to ignore everything to do with FooObject - I do not care what
 * it is because I do not store its value. How do I do this? */
mockObject.write(param);

replay(mockObject);

someOtherObjectThatCallsAboveMockObject.process(mockObject);

verify(mockObject);

So are there any EasyMock experts out there? I'm not concerned about the design of the underlying method that I'm calling and not storing the return value because the actually implementation is coming from a third-party networking library (Apache Mina) and I have no control over the API.

EDIT: Conclusion reached some time later

I dumped EasyMock because it wasn't easy and went for Mockito.

Was it helpful?

Solution

Instead of

mockObject.write(param)

write

EasyMock.expect( mockObject.write(param) ).andReturn( /* return value here */ );

You still need to return a value for the code to be correct but you can ignore the value further on in the test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top