Package org.mockito.internal.invocation
Class InterceptedInvocation
- java.lang.Object
-
- org.mockito.internal.invocation.InterceptedInvocation
-
- All Implemented Interfaces:
java.io.Serializable,VerificationAwareInvocation,DescribedInvocation,Invocation,InvocationOnMock
public class InterceptedInvocation extends java.lang.Object implements Invocation, VerificationAwareInvocation
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object[]argumentsprivate booleanisIgnoredForVerificationprivate Locationlocationprivate MockitoMethodmockitoMethodprivate MockReference<java.lang.Object>mockRefstatic RealMethodNO_OPprivate java.lang.Object[]rawArgumentsprivate RealMethodrealMethodprivate intsequenceNumberprivate static longserialVersionUIDprivate StubInfostubInfoprivate booleanverified
-
Constructor Summary
Constructors Constructor Description InterceptedInvocation(MockReference<java.lang.Object> mockRef, MockitoMethod mockitoMethod, java.lang.Object[] arguments, RealMethod realMethod, Location location, int sequenceNumber)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.ObjectcallRealMethod()calls real methodprivate booleanequalArguments(java.lang.Object[] arguments)booleanequals(java.lang.Object o)<T> TgetArgument(int index)Returns casted argument at the given index.<T> TgetArgument(int index, java.lang.Class<T> clazz)Returns casted argument at the given index.java.lang.Object[]getArguments()Returns arguments passed to the method.java.util.List<ArgumentMatcher>getArgumentsAsMatchers()Wraps each argument usingArgumentMatchers.eq(Object)orAdditionalMatchers.aryEq(Object[])Used internally for the purposes of human-readable invocation printing.LocationgetLocation()The place in the code where the invocation happened.java.lang.reflect.MethodgetMethod()returns the methodjava.lang.ObjectgetMock()returns the mock objectMockitoMethodgetMockitoMethod()Deprecated.Not used by Mockito but by mockito-scalaMockReference<java.lang.Object>getMockRef()Deprecated.Not used by Mockito but by mockito-scalajava.lang.Object[]getRawArguments()Returns unprocessed arguments whereasInvocationOnMock.getArguments()returns arguments already processed (e.g.java.lang.Class<?>getRawReturnType()Returns unprocessed arguments whereasInvocationOnMock.getArguments()returns arguments already processed (e.g.RealMethodgetRealMethod()Deprecated.Not used by Mockito but by mockito-scalaintgetSequenceNumber()inthashCode()voidignoreForVerification()Configures this invocation to be ignored for verify-no-more-invocations or verification in order.booleanisIgnoredForVerification()Informs if the invocation participates in verify-no-more-invocations or verification in order.booleanisVerified()voidmarkStubbed(StubInfo stubInfo)Marks this invocation as stubbed.voidmarkVerified()Marks this invocation as verified so that it will not cause verification error atMockito.verifyNoMoreInteractions(Object...)StubInfostubInfo()java.lang.StringtoString()Describes the invocation in the human friendly way.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
mockRef
private final MockReference<java.lang.Object> mockRef
-
mockitoMethod
private final MockitoMethod mockitoMethod
-
arguments
private final java.lang.Object[] arguments
-
rawArguments
private final java.lang.Object[] rawArguments
-
realMethod
private final RealMethod realMethod
-
sequenceNumber
private final int sequenceNumber
-
location
private final Location location
-
verified
private boolean verified
-
isIgnoredForVerification
private boolean isIgnoredForVerification
-
stubInfo
private StubInfo stubInfo
-
NO_OP
public static final RealMethod NO_OP
-
-
Constructor Detail
-
InterceptedInvocation
public InterceptedInvocation(MockReference<java.lang.Object> mockRef, MockitoMethod mockitoMethod, java.lang.Object[] arguments, RealMethod realMethod, Location location, int sequenceNumber)
-
-
Method Detail
-
isVerified
public boolean isVerified()
- Specified by:
isVerifiedin interfaceInvocation- Specified by:
isVerifiedin interfaceVerificationAwareInvocation- Returns:
- whether the invocation has been already verified.
Needed for
Mockito.verifyNoMoreInteractions(Object...)
-
getSequenceNumber
public int getSequenceNumber()
- Specified by:
getSequenceNumberin interfaceInvocation- Returns:
- the sequence number of the Invocation. Useful to determine the order of invocations. Used by verification in order.
-
getLocation
public Location getLocation()
Description copied from interface:DescribedInvocationThe place in the code where the invocation happened.- Specified by:
getLocationin interfaceDescribedInvocation- Specified by:
getLocationin interfaceInvocation- Returns:
- the location in code of this invocation.
-
getRawArguments
public java.lang.Object[] getRawArguments()
Description copied from interface:InvocationOnMockReturns unprocessed arguments whereasInvocationOnMock.getArguments()returns arguments already processed (e.g. varargs expended, etc.).- Specified by:
getRawArgumentsin interfaceInvocationOnMock- Returns:
- unprocessed arguments, exactly as provided to this invocation.
-
getRawReturnType
public java.lang.Class<?> getRawReturnType()
Description copied from interface:InvocationReturns unprocessed arguments whereasInvocationOnMock.getArguments()returns arguments already processed (e.g. varargs expended, etc.).- Specified by:
getRawReturnTypein interfaceInvocation- Returns:
- unprocessed arguments, exactly as provided to this invocation.
-
markVerified
public void markVerified()
Description copied from interface:InvocationMarks this invocation as verified so that it will not cause verification error atMockito.verifyNoMoreInteractions(Object...)- Specified by:
markVerifiedin interfaceInvocation
-
stubInfo
public StubInfo stubInfo()
- Specified by:
stubInfoin interfaceInvocation- Returns:
- the stubbing information for this invocation. May return null - this means the invocation was not stubbed.
-
markStubbed
public void markStubbed(StubInfo stubInfo)
Description copied from interface:InvocationMarks this invocation as stubbed.- Specified by:
markStubbedin interfaceInvocation- Parameters:
stubInfo- the information about stubbing.
-
isIgnoredForVerification
public boolean isIgnoredForVerification()
Description copied from interface:InvocationInforms if the invocation participates in verify-no-more-invocations or verification in order.- Specified by:
isIgnoredForVerificationin 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:InvocationConfigures this invocation to be ignored for verify-no-more-invocations or verification in order. See alsoInvocation.isIgnoredForVerification()- Specified by:
ignoreForVerificationin interfaceInvocation
-
getMock
public java.lang.Object getMock()
Description copied from interface:InvocationOnMockreturns the mock object- Specified by:
getMockin interfaceInvocationOnMock- Returns:
- mock object
-
getMethod
public java.lang.reflect.Method getMethod()
Description copied from interface:InvocationOnMockreturns the method- Specified by:
getMethodin interfaceInvocationOnMock- Returns:
- method
-
getArguments
public java.lang.Object[] getArguments()
Description copied from interface:InvocationOnMockReturns arguments passed to the method. Vararg are expanded in this array.- Specified by:
getArgumentsin interfaceInvocationOnMock- Returns:
- arguments
-
getArgument
public <T> T getArgument(int index)
Description copied from interface:InvocationOnMockReturns 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:
getArgumentin interfaceInvocationOnMock- Parameters:
index- argument index- Returns:
- casted argument at the given index
-
getArgument
public <T> T getArgument(int index, java.lang.Class<T> clazz)Description copied from interface:InvocationOnMockReturns 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:
getArgumentin 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
public java.util.List<ArgumentMatcher> getArgumentsAsMatchers()
Description copied from interface:InvocationWraps each argument usingArgumentMatchers.eq(Object)orAdditionalMatchers.aryEq(Object[])Used internally for the purposes of human-readable invocation printing.- Specified by:
getArgumentsAsMatchersin interfaceInvocation- Returns:
- a list of
ArgumentMatcherwrapping each of this invocation arguments
-
callRealMethod
public java.lang.Object callRealMethod() throws java.lang.ThrowableDescription copied from interface:InvocationOnMockcalls real methodWarning: depending on the real implementation it might throw exceptions
- Specified by:
callRealMethodin interfaceInvocationOnMock- Returns:
- whatever the real method returns / throws
- Throws:
java.lang.Throwable- in case real method throws
-
getMockRef
@Deprecated public MockReference<java.lang.Object> getMockRef()
Deprecated.Not used by Mockito but by mockito-scala
-
getMockitoMethod
@Deprecated public MockitoMethod getMockitoMethod()
Deprecated.Not used by Mockito but by mockito-scala
-
getRealMethod
@Deprecated public RealMethod getRealMethod()
Deprecated.Not used by Mockito but by mockito-scala
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
equalArguments
private boolean equalArguments(java.lang.Object[] arguments)
-
toString
public java.lang.String toString()
Description copied from interface:DescribedInvocationDescribes the invocation in the human friendly way.- Specified by:
toStringin interfaceDescribedInvocation- Overrides:
toStringin classjava.lang.Object- Returns:
- the description of this invocation.
-
-