Generally, if the test fails, you should be able to determine what is wrong with the device under test. Avoid writing custom patterns specifically for one test. If a method needs to return more than one value, it is usually sufficient to simply drown out the method, returning the values ββin the order that the test predicts.
eg.
when(mock.method(any(Object.class))).thenReturn(result1, result2, result3);
This will return result 1, the first call, result2 to the second, etc.
There are obviously scenarios where this is not enough, but more often a simpler test is the best.
source share