16

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.

leinra
  • 163
  • 1
  • 1
  • 4

1 Answers1

30
when(myObject.someMethod()).thenReturn(someMockObject);
// run test
verify(myObject, times(n)).someMethod();

See the documentation for more conversion examples.

Alex DiCarlo
  • 4,851
  • 18
  • 34
  • 1
    Also note that Mockito generally discourages overdoing verify. Think about whether you really need to verify each call. (Most of the time, these are just dependencies that will blow up if they mess up anyway.) – Barett Nov 18 '13 at 20:57