I have a method that returns void in a class that is a dependency of the class I want to test.
This class is huge and I\'m only using this single method from it. I n
If you just call the void method for each time you're expecting it to be invoked and then invoke EasyMock.expectLastCall() prior to calling replay(), Easymock will “remember” each invocation.
So I don’t think you need to explicitly call expect() (other than lastCall) since you’re not expecting anything from a void method, except its invocation.
Thanks Chris!
“Fun With EasyMock” by fellow StackOverflow user Burt Beckwith is a good blog post that provides more detail. Notable excerpt:
Basically the flow that I tend to use is:
- Create a mock
- call
expect(mock.[method call]).andReturn([result])for each expected call- call
mock.[method call], thenEasyMock.expectLastCall()for each expected void call- call
replay(mock)to switch from “record” mode to “playback” mode- inject the mock as needed
- call the test method
- call
verify(mock)to assure that all expected calls happened