使用EasyMock + PowerMock时如何设置void方法的expect调用次数?

时间:2013-09-02 07:23:45

标签: java easymock powermock

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

我想为这个预期的void方法设置调用计数,但我不知道该怎么做。

1 个答案:

答案 0 :(得分:3)

要预期最后一次通话3次,您可以使用expectLastCall方法:

// mockRandomAccessFile is a mock
mockRandomAccessFile.seek(0L);
EasyMock.expectLastCall().times(3);