org.mockito.stubbing.answers
Class ReturnsElementsOf

java.lang.Object
  extended by org.mockito.stubbing.answers.ReturnsElementsOf
All Implemented Interfaces:
Answer

public class ReturnsElementsOf
extends java.lang.Object
implements Answer

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)));
 


Constructor Summary
ReturnsElementsOf(java.util.Collection elements)
           
 
Method Summary
 java.lang.Object answer(InvocationOnMock invocation)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReturnsElementsOf

public ReturnsElementsOf(java.util.Collection elements)
Method Detail

answer

public java.lang.Object answer(InvocationOnMock invocation)
                        throws java.lang.Throwable
Specified by:
answer in interface Answer
Parameters:
invocation - the invocation on the mock.
Returns:
the value to be returned
Throws:
java.lang.Throwable - the throwable to be thrown