org.mockito.internal.stubbing.answers
Class ReturnsElementsOf
java.lang.Object
org.mockito.internal.stubbing.answers.ReturnsElementsOf
- All Implemented Interfaces:
- Answer<java.lang.Object>
- Direct Known Subclasses:
- ReturnsElementsOf
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()).thenReturn(new ReturnsElementsOf(Arrays.asList(1, 2, 3)));
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReturnsElementsOf
public ReturnsElementsOf(java.util.Collection<?> elements)
answer
public java.lang.Object answer(InvocationOnMock invocation)
throws java.lang.Throwable
- Specified by:
answer
in interface Answer<java.lang.Object>
- Parameters:
invocation
- the invocation on the mock.
- Returns:
- the value to be returned
- Throws:
java.lang.Throwable
- the throwable to be thrown