ReturnsElementsOf
Date: 2015-09-18

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()).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`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReturnsElementsOf(java.util.Collection<?> elements)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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<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