Package org.mockito.internal.invocation
Class InterceptedInvocation
java.lang.Object
org.mockito.internal.invocation.InterceptedInvocation
- All Implemented Interfaces:
Serializable
,VerificationAwareInvocation
,DescribedInvocation
,Invocation
,InvocationOnMock
public class InterceptedInvocation
extends Object
implements Invocation, VerificationAwareInvocation
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInterceptedInvocation
(MockReference<Object> mockRef, MockitoMethod mockitoMethod, Object[] arguments, RealMethod realMethod, Location location, int sequenceNumber) -
Method Summary
Modifier and TypeMethodDescriptioncalls real methodboolean
<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.Wraps each argument usingArgumentMatchers.eq(Object)
orAdditionalMatchers.aryEq(Object[])
Used internally for the purposes of human-readable invocation printing.The place in the code where the invocation happened.returns the methodgetMock()
returns the mock objectDeprecated.Not used by Mockito but by mockito-scalaDeprecated.Not used by Mockito but by mockito-scalaObject[]
Returns unprocessed arguments whereasInvocationOnMock.getArguments()
returns arguments already processed (e.g.Class
<?> Returns unprocessed arguments whereasInvocationOnMock.getArguments()
returns arguments already processed (e.g.Deprecated.Not used by Mockito but by mockito-scalaint
int
hashCode()
void
Configures this invocation to be ignored for verify-no-more-invocations or verification in order.boolean
Informs if the invocation participates in verify-no-more-invocations or verification in order.boolean
void
markStubbed
(StubInfo stubInfo) Marks this invocation as stubbed.void
Marks this invocation as verified so that it will not cause verification error atMockito.verifyNoMoreInteractions(Object...)
stubInfo()
toString()
Describes the invocation in the human friendly way.
-
Field Details
-
NO_OP
-
-
Constructor Details
-
InterceptedInvocation
public InterceptedInvocation(MockReference<Object> mockRef, MockitoMethod mockitoMethod, Object[] arguments, RealMethod realMethod, Location location, int sequenceNumber)
-
-
Method Details
-
isVerified
public boolean isVerified()- Specified by:
isVerified
in interfaceInvocation
- Specified by:
isVerified
in interfaceVerificationAwareInvocation
- Returns:
- whether the invocation has been already verified.
Needed for
Mockito.verifyNoMoreInteractions(Object...)
-
getSequenceNumber
public int getSequenceNumber()- Specified by:
getSequenceNumber
in interfaceInvocation
- Returns:
- the sequence number of the Invocation. Useful to determine the order of invocations. Used by verification in order.
-
getLocation
Description copied from interface:DescribedInvocation
The place in the code where the invocation happened.- Specified by:
getLocation
in interfaceDescribedInvocation
- Specified by:
getLocation
in interfaceInvocation
- Returns:
- the location in code of this invocation.
-
getRawArguments
Description copied from interface:InvocationOnMock
Returns unprocessed arguments whereasInvocationOnMock.getArguments()
returns arguments already processed (e.g. varargs expended, etc.).- Specified by:
getRawArguments
in interfaceInvocationOnMock
- Returns:
- unprocessed arguments, exactly as provided to this invocation.
-
getRawReturnType
Description copied from interface:Invocation
Returns unprocessed arguments whereasInvocationOnMock.getArguments()
returns arguments already processed (e.g. varargs expended, etc.).- Specified by:
getRawReturnType
in interfaceInvocation
- Returns:
- unprocessed arguments, exactly as provided to this invocation.
-
markVerified
public void markVerified()Description copied from interface:Invocation
Marks this invocation as verified so that it will not cause verification error atMockito.verifyNoMoreInteractions(Object...)
- Specified by:
markVerified
in interfaceInvocation
-
stubInfo
- Specified by:
stubInfo
in interfaceInvocation
- Returns:
- the stubbing information for this invocation. May return null - this means the invocation was not stubbed.
-
markStubbed
Description copied from interface:Invocation
Marks this invocation as stubbed.- Specified by:
markStubbed
in interfaceInvocation
- Parameters:
stubInfo
- the information about stubbing.
-
isIgnoredForVerification
public boolean isIgnoredForVerification()Description copied from interface:Invocation
Informs if the invocation participates in verify-no-more-invocations or verification in order.- Specified by:
isIgnoredForVerification
in interfaceInvocation
- Returns:
- whether this invocation should be ignored for the purposes of verify-no-more-invocations or verification in order.
-
ignoreForVerification
public void ignoreForVerification()Description copied from interface:Invocation
Configures this invocation to be ignored for verify-no-more-invocations or verification in order. See alsoInvocation.isIgnoredForVerification()
- Specified by:
ignoreForVerification
in interfaceInvocation
-
getMock
Description copied from interface:InvocationOnMock
returns the mock object- Specified by:
getMock
in interfaceInvocationOnMock
- Returns:
- mock object
-
getMethod
Description copied from interface:InvocationOnMock
returns the method- Specified by:
getMethod
in interfaceInvocationOnMock
- Returns:
- method
-
getArguments
Description copied from interface:InvocationOnMock
Returns arguments passed to the method. Vararg are expanded in this array.- Specified by:
getArguments
in interfaceInvocationOnMock
- Returns:
- arguments
-
getArgument
public <T> T getArgument(int index) Description copied from interface:InvocationOnMock
Returns casted argument at the given index. Can lookup in expanded arguments formInvocationOnMock.getArguments()
. This method is preferred overInvocationOnMock.getArgument(int, Class)
for readability. Please read the documentation ofInvocationOnMock.getArgument(int, Class)
for an overview of situations when that method is preferred over this one.- Specified by:
getArgument
in interfaceInvocationOnMock
- Parameters:
index
- argument index- Returns:
- casted argument at the given index
-
getArgument
Description copied from interface:InvocationOnMock
Returns casted argument at the given index. This method is analogous toInvocationOnMock.getArgument(int)
, but is necessary to circumvent issues when dealing with generics. In general,InvocationOnMock.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
InvocationOnMock.getArgument(int)
. - You want to directly pass the result of the invocation into a function that accepts a generic parameter.
InvocationOnMock.getArgument(int)
instead, you can circumvent the compilation issues by storing the intermediate result into a local variable with the correct type.- Specified by:
getArgument
in interfaceInvocationOnMock
- 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
-
getArgumentsAsMatchers
Description copied from interface:Invocation
Wraps each argument usingArgumentMatchers.eq(Object)
orAdditionalMatchers.aryEq(Object[])
Used internally for the purposes of human-readable invocation printing.- Specified by:
getArgumentsAsMatchers
in interfaceInvocation
- Returns:
- a list of
ArgumentMatcher
wrapping each of this invocation arguments
-
callRealMethod
Description copied from interface:InvocationOnMock
calls real methodWarning: depending on the real implementation it might throw exceptions
- Specified by:
callRealMethod
in interfaceInvocationOnMock
- Returns:
- whatever the real method returns / throws
- Throws:
Throwable
- in case real method throws
-
getMockRef
Deprecated.Not used by Mockito but by mockito-scala -
getMockitoMethod
Deprecated.Not used by Mockito but by mockito-scala -
getRealMethod
Deprecated.Not used by Mockito but by mockito-scala -
hashCode
public int hashCode() -
equals
-
toString
Description copied from interface:DescribedInvocation
Describes the invocation in the human friendly way.- Specified by:
toString
in interfaceDescribedInvocation
- Overrides:
toString
in classObject
- Returns:
- the description of this invocation.
-