What is the Mockito equivalent of expect().andReturn().times()

leinra picture leinra · Jan 18, 2013 · Viewed 20.5k times · Source

I've been experimenting the Mockito equivalent of the

EasyMock.expect(someMethod()).andReturn(someMockObject).times(n);

but I can't figure it out.

A little help on this, please?

Thanks in advance.

Answer

Alex DiCarlo picture Alex DiCarlo · Jan 18, 2013
when(myObject.someMethod()).thenReturn(someMockObject);
// run test
verify(myObject, times(n)).someMethod();

See the documentation for more conversion examples.