Class ReturnsArgumentAt

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

public class ReturnsArgumentAt extends Object implements Answer<Object>, Serializable
Returns the passed parameter identity at specified index.

The argumentIndex represents the index in the argument array of the invocation.

If this number equals -1 then the last argument is returned.

Since:
1.9.5
See Also:
  • Field Details

  • Constructor Details

    • ReturnsArgumentAt

      public ReturnsArgumentAt(int wantedArgumentPosition)
      Build the identity answer to return the argument at the given position in the argument array.
      Parameters:
      wantedArgumentPosition - The position of the argument identity to return in the invocation. Using -1 indicates the last argument.
  • Method Details

    • answer

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

      public int wantedArgumentPosition()
    • validateIndexWithinInvocationRange

      public void validateIndexWithinInvocationRange(InvocationOnMock invocation)
    • returnedTypeOnSignature

      public Class returnedTypeOnSignature(InvocationOnMock invocation)