Package org.mockito.invocation
Interface InvocationOnMock
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
Invocation
An invocation on a mock.
A placeholder for mock, the method that was called and the arguments that were passed.
-
Method Summary
Modifier and TypeMethodDescriptioncalls real method<T> T
getArgument
(int index) Returns casted argument at the given index.<T> T
getArgument
(int index, Class<T> clazz) Returns casted argument at the given index.Object[]
Returns arguments passed to the method.returns the methodgetMock()
returns the mock objectObject[]
Returns unprocessed arguments whereasgetArguments()
returns arguments already processed (e.g.
-
Method Details
-
getMock
Object getMock()returns the mock object- Returns:
- mock object
-
getMethod
Method getMethod()returns the method- Returns:
- method
-
getRawArguments
Object[] getRawArguments()Returns unprocessed arguments whereasgetArguments()
returns arguments already processed (e.g. varargs expended, etc.).- Returns:
- unprocessed arguments, exactly as provided to this invocation.
- Since:
- 4.7.0
-
getArguments
Object[] getArguments()Returns arguments passed to the method. Vararg are expanded in this array.- Returns:
- arguments
-
getArgument
<T> T getArgument(int index) Returns casted argument at the given index. Can lookup in expanded arguments formgetArguments()
. This method is preferred overgetArgument(int, Class)
for readability. Please read the documentation ofgetArgument(int, Class)
for an overview of situations when that method is preferred over this one.- Parameters:
index
- argument index- Returns:
- casted argument at the given index
- Since:
- 2.1.0
-
getArgument
Returns casted argument at the given index. This method is analogous togetArgument(int)
, but is necessary to circumvent issues when dealing with generics. In general,getArgument(int)
is the appropriate function to use. This particular function is only necessary if you are doing one of the following things:- You want to directly invoke a method on the result of
getArgument(int)
. - You want to directly pass the result of the invocation into a function that accepts a generic parameter.
getArgument(int)
instead, you can circumvent the compilation issues by storing the intermediate result into a local variable with the correct type.- Parameters:
index
- argument indexclazz
- class to cast the argument to- Returns:
- casted argument at the given index
- You want to directly invoke a method on the result of
-
callRealMethod
calls real methodWarning: depending on the real implementation it might throw exceptions
- Returns:
- whatever the real method returns / throws
- Throws:
Throwable
- in case real method throws
-