Class ReturnsElementsOf
- java.lang.Object
-
- org.mockito.internal.stubbing.answers.ReturnsElementsOf
-
- All Implemented Interfaces:
Answer<java.lang.Object>
public class ReturnsElementsOf extends java.lang.Object implements Answer<java.lang.Object>
Returns elements of the collection. Keeps returning the last element forever. Might be useful on occasion when you have a collection of elements to return.//this: when(mock.foo()).thenReturn(1, 2, 3); //is equivalent to: when(mock.foo()).thenAnswer(new ReturnsElementsOf(Arrays.asList(1, 2, 3)));
Also you might better want to use the static factory there
AdditionalAnswers.returnsElementsOf(java.util.Collection)
- See Also:
AdditionalAnswers
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<java.lang.Object>
elements
-
Constructor Summary
Constructors Constructor Description ReturnsElementsOf(java.util.Collection<?> elements)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
answer(InvocationOnMock invocation)
-
-
-
Method Detail
-
answer
public java.lang.Object answer(InvocationOnMock invocation) throws java.lang.Throwable
-
-