Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using easymock, repeated void method call

Tags:

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

like image 445
Hendrik Avatar asked Aug 03 '09 12:08

Hendrik


People also ask

How do you expect a void method to call in 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.

What is EasyMock expectLastCall?

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.

What does EasyMock Replay do?

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).

How does EasyMock work?

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.


1 Answers

Call the void method of the mock. Afterwards use EasyMock.expectLastCall().anyTimes()

like image 177
Arne Burmeister Avatar answered Oct 31 '22 05:10

Arne Burmeister