EasyMock.expectLastCall().anyTimes() 等效的 Mockito 验证是什么?

What's the Mockito verify for EasyMock.expectLastCall().anyTimes() equivalent?

正在将一些测试从 EasyMock 迁移到 Mockito。

EasyMock 代码如下:

Some mock = EasyMock.createMock(Some.class);
mock.someMethod(argMatcher);
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(mock);

如何使用 Mockito 进行等效(或类似)模拟验证?

我会这样写一个测试:

Some mock = Mockito.mock(Some.class);
Mockito.when(mock.someMethod(argMatcher)).thenReturn(aReturnObject);
yourTestedObject.setSome(mock)

yourTestedObject.someTestedMethodWhichUseSomeClass();

Mockito.verify(mock, Mockito.atLeastOnce()).someMethod(argMatcher);

对于 void 方法:

Some mock = Mockito.mock(Some.class);
Mockito.doNothing().when(mock).someMethod(argMatcher);
yourTestedObject.setSome(mock);

yourTestedObject.someTestMethodWhichUseSomeClass();

Mockito.verify(mock, Mockito.atLeastOnce()).someMethod(argMatcher);