Class ReturnsElementsOf

java.lang.Object
org.mockito.internal.stubbing.answers.ReturnsElementsOf
All Implemented Interfaces:
Answer<Object>

public class ReturnsElementsOf extends Object implements Answer<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:
  • Field Details

  • Constructor Details

    • ReturnsElementsOf

      public ReturnsElementsOf(Collection<?> elements)
  • Method Details