Class ReturnsArgumentAt
java.lang.Object
org.mockito.internal.stubbing.answers.ReturnsArgumentAt
- All Implemented Interfaces:
Serializable
,Answer<Object>
,ValidableAnswer
public class ReturnsArgumentAt
extends Object
implements Answer<Object>, ValidableAnswer, 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
private static final long
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionReturnsArgumentAt
(int wantedArgumentPosition) Build the identity answer to return the argument at the given position in the argument array. -
Method Summary
Modifier and TypeMethodDescriptionanswer
(InvocationOnMock invocation) private Class
<?> inferArgumentType
(Invocation invocation, int argumentIndex) private int
inferWantedArgumentPosition
(InvocationOnMock invocation) private int
inferWantedRawArgumentPosition
(InvocationOnMock invocation) private void
validateArgumentTypeCompatibility
(Invocation invocation, int argumentPosition) void
validateFor
(InvocationOnMock invocationOnMock) Validation of the answer at stub time for the given invocation.private void
validateIndexWithinInvocationRange
(InvocationOnMock invocation, int argumentPosition) private void
validateIndexWithinTheoreticalInvocationRange
(InvocationOnMock invocation, int argumentPosition) private boolean
private boolean
wantedArgumentPositionIsValidForTheoreticalInvocation
(InvocationOnMock invocation, int argumentPosition)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
LAST_ARGUMENT
public static final int LAST_ARGUMENT- See Also:
-
wantedArgumentPosition
private final int wantedArgumentPosition
-
-
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 (LAST_ARGUMENT
).
-
-
Method Details
-
answer
-
validateFor
Description copied from interface:ValidableAnswer
Validation 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:
validateFor
in interfaceValidableAnswer
- Parameters:
invocationOnMock
- The stubbed invocation
-
inferWantedArgumentPosition
-
inferWantedRawArgumentPosition
-
validateIndexWithinInvocationRange
-
validateIndexWithinTheoreticalInvocationRange
private void validateIndexWithinTheoreticalInvocationRange(InvocationOnMock invocation, int argumentPosition) -
validateArgumentTypeCompatibility
-
wantedArgIndexIsVarargAndSameTypeAsReturnType
-
wantedArgumentPositionIsValidForTheoreticalInvocation
private boolean wantedArgumentPositionIsValidForTheoreticalInvocation(InvocationOnMock invocation, int argumentPosition) -
inferArgumentType
-