Class ReturnsArgumentAt
- java.lang.Object
-
- org.mockito.internal.stubbing.answers.ReturnsArgumentAt
-
- All Implemented Interfaces:
java.io.Serializable,Answer<java.lang.Object>,ValidableAnswer
public class ReturnsArgumentAt extends java.lang.Object implements Answer<java.lang.Object>, ValidableAnswer, java.io.Serializable
Returns the passed parameter identity at specified index.The
argumentIndexrepresents 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:
AdditionalAnswers, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intLAST_ARGUMENTprivate static longserialVersionUIDprivate intwantedArgumentPosition
-
Constructor Summary
Constructors Constructor Description ReturnsArgumentAt(int wantedArgumentPosition)Build the identity answer to return the argument at the given position in the argument array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectanswer(InvocationOnMock invocation)private java.lang.Class<?>inferArgumentType(Invocation invocation, int argumentIndex)private intinferWantedArgumentPosition(InvocationOnMock invocation)private intinferWantedRawArgumentPosition(InvocationOnMock invocation)private voidvalidateArgumentTypeCompatibility(Invocation invocation, int argumentPosition)voidvalidateFor(InvocationOnMock invocationOnMock)Validation of the answer at stub time for the given invocation.private voidvalidateIndexWithinInvocationRange(InvocationOnMock invocation, int argumentPosition)private voidvalidateIndexWithinTheoreticalInvocationRange(InvocationOnMock invocation, int argumentPosition)private booleanwantedArgIndexIsVarargAndSameTypeAsReturnType(InvocationOnMock invocation)private booleanwantedArgumentPositionIsValidForTheoreticalInvocation(InvocationOnMock invocation, int argumentPosition)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
LAST_ARGUMENT
public static final int LAST_ARGUMENT
- See Also:
- Constant Field Values
-
wantedArgumentPosition
private final int wantedArgumentPosition
-
-
Constructor Detail
-
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-1indicates the last argument (LAST_ARGUMENT).
-
-
Method Detail
-
answer
public java.lang.Object answer(InvocationOnMock invocation) throws java.lang.Throwable
-
validateFor
public void validateFor(InvocationOnMock invocationOnMock)
Description copied from interface:ValidableAnswerValidation of the answer at stub time for the given invocation.This method will be called by Mockito.
The implementation must throw an MockitoException to indicate that this answer is not valid for the given invocation. If the validation succeed the implementation must simply return without throwing.
- Specified by:
validateForin interfaceValidableAnswer- Parameters:
invocationOnMock- The stubbed invocation
-
inferWantedArgumentPosition
private int inferWantedArgumentPosition(InvocationOnMock invocation)
-
inferWantedRawArgumentPosition
private int inferWantedRawArgumentPosition(InvocationOnMock invocation)
-
validateIndexWithinInvocationRange
private void validateIndexWithinInvocationRange(InvocationOnMock invocation, int argumentPosition)
-
validateIndexWithinTheoreticalInvocationRange
private void validateIndexWithinTheoreticalInvocationRange(InvocationOnMock invocation, int argumentPosition)
-
validateArgumentTypeCompatibility
private void validateArgumentTypeCompatibility(Invocation invocation, int argumentPosition)
-
wantedArgIndexIsVarargAndSameTypeAsReturnType
private boolean wantedArgIndexIsVarargAndSameTypeAsReturnType(InvocationOnMock invocation)
-
wantedArgumentPositionIsValidForTheoreticalInvocation
private boolean wantedArgumentPositionIsValidForTheoreticalInvocation(InvocationOnMock invocation, int argumentPosition)
-
inferArgumentType
private java.lang.Class<?> inferArgumentType(Invocation invocation, int argumentIndex)
-
-