11

I'm just wondering if it is possible using Junit and easymock to ignore unexpected method calls?

I.e. instead of the test failing I want to be able to say - "at this point - ignore any unexpected method calls and just continue with the test as normal'

Thanks

Rory
  • 1,805
  • 7
  • 31
  • 45

1 Answers1

19

With EasyMock you can create a nice mock, which unlike a normal mock object does not throw assertion errors if an unexpected/recorded call occurs. To quote the easymock documentation...

On a Mock Object returned by createMock() the default behavior for all methods is to throw an AssertionError for all unexpected method calls. If you would like a "nice" Mock Object that by default allows all method calls and returns appropriate empty values (0, null or false), use createNiceMock() instead.

To create a nice mock, use the static createNiceMock(Class class) method on the Easymock class...

SomeClass someClassNiceMock = EasyMock.createNiceMock(SomeClass.class);

Reference: http://easymock.org/user-guide.html#mocking-nice

frostmatthew
  • 3,260
  • 4
  • 40
  • 50
mmccomb
  • 13,516
  • 5
  • 39
  • 46