0
File mockFile = createMockAndExpectNew(File.class, fileParentPath+fileName);
RandomAccessFile mockRandomAccessFile = createMockAndExpectNew(RandomAccessFile.class, mockFile, "rw");
mockRandomAccessFile.seek(0L);

I want to set invocation counts for this expected void method, but I don't know what to do.

Rekoolno
  • 85
  • 1
  • 3
  • 11

1 Answers1

4

To expect the last call 3 times, you can use the expectLastCall method:

// mockRandomAccessFile is a mock
mockRandomAccessFile.seek(0L);
EasyMock.expectLastCall().times(3);
LaurentG
  • 11,128
  • 9
  • 51
  • 66
  • Unfortunately I failed: 'mockRandomAccessFile.seek(0L); EasyMock.expectLastCall.times(0);' And I got this: java.lang.IllegalArgumentException: maximum must be >= 1 – Rekoolno Sep 02 '13 at 08:06
  • 1
    You have to use strick mocks, don't expect this method call and verify the mock at the end of the execution. This question explains in details: http://stackoverflow.com/questions/3710717/test-that-void-method-didnt-get-called-with-easymock – LaurentG Sep 02 '13 at 08:15