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?
andVoid() If we just want to mock void method and don't want to perform any logic, we can simply use expectLastCall(). andVoid() right after calling void method on mocked object. You can checkout complete project and more EasyMock examples from our GitHub Repository.
Mockito provides following methods that can be used to mock void methods. doAnswer() : We can use this to perform some operations when a mocked object method is called that is returning void. doThrow() : We can use doThrow() when we want to stub a void method that throws exception.
The expect() method tells EasyMock to simulate a method with certain arguments. The andReturn() method defines the return value of this method for the specified method parameters. The times() method defines how often the Mock object will be called. The replay() method is called to make the Mock object available.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With