How to expect void method call with any argument using EasyMock

shantanu picture shantanu · Jun 15, 2013 · Viewed 8.8k times · Source

As a part of unit test I need to mock a void function(Which accept any non-primitive paramter. e.g. MAP) call with any argument.

mockObj.myMethod(<anyObject>)

Is it possible to do this with EasyMock?

Answer

John B picture John B · Jun 17, 2013

Use either of the anyObject methods: anyObject() or anyObject(T)

So

 expect(mockObj.myMethod(anyObject()));

See the Flexible Expectations with Argument Matchers section of the documentation