Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test that void method didn't get called with EasyMock

Tags:

Is this possible? I tried with EasyMock.expectLastCall().times(0); but EasyMock complains that times must be >=1

like image 906
nkr1pt Avatar asked Sep 14 '10 16:09

nkr1pt


People also ask

How do you test a void on 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?

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?

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. expect(…): with this method, we can set expectations, including calls, results, and exceptions, for associated recording actions.


1 Answers

You could use .andThrow(new AssertionFailedError()).anyTimes(); - this is the same exception that Assert.fail() throws, but is less verbose than making an Answer.

like image 152
Dawood ibn Kareem Avatar answered Oct 15 '22 17:10

Dawood ibn Kareem