Mockito stubbing - returning a repeat value X number of times

Viewed 24

I know that by creating a stub in Mockito, consecutive values can be returned from a mock like so:

when(mockedObject.doSomething()).thenReturn(1, 1, 1, 1, 5);

or

when(mockedObject.doSomething()).thenReturn(1).thenReturn(1).thenReturn(1).thenReturn(1).thenReturn(5);

Is it possible to specify a repeat number for a specific return value? Something like this:

when(mockedObject.doSomething()).thenReturn(1, times(4)).thenReturn(5);
0 Answers
Related