I am new to easymock.
I am trying to mock a service where one of the methods is a void method that will get called an unknown (and large) number of times. How do I specify that any number of calls is allowed?
I know how to do it for methods that have a non-void return type.
Thanks
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.
method(obj); The API doc for EasyMock says this about expectLastCall() : Returns the expectation setter for the last expected invocation in the current thread. This method is used for expected invocations on void methods. java unit-testing easymock.
The replay method is used to pass the mock from recording (where you record the method you expect to be called) to replaying state (where you actually test).
easymock. EasyMock: mock(…): generates a mock of the target class, be it a concrete class or an interface. Once created, a mock is in “recording” mode, meaning that EasyMock will record any action the Mock Object takes, and replay them in the “replay” mode.
Call the void method of the mock. Afterwards use EasyMock.expectLastCall().anyTimes()
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