Package mockit

Class Invocation

java.lang.Object
mockit.Invocation
Direct Known Subclasses:
BaseInvocation

public class Invocation extends Object
A context object representing the current invocation to a mocked or faked method/constructor, to be passed as the first parameter of the corresponding delegate/fake method implementation.

With the Mocking API, this parameter can appear in delegate methods implemented in Delegate classes. With the Faking API, it can appear in @Mock methods.

See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Invocation(Object invokedInstance, Object[] invokedArguments, @org.checkerframework.checker.index.qual.NonNegative int invocationCount)
    For internal use only.
  • Method Summary

    Modifier and Type
    Method
    Description
    final @org.checkerframework.checker.index.qual.NonNegative int
    Returns the current invocation count.
    final int
    Returns the index for the current invocation.
    final Object[]
    Returns the actual argument values passed in the invocation to the target method/constructor.
    final <T> T
    Returns the instance on which the current invocation was made, or null for a static method invocation.
    final <M extends Member>
    M
    Returns the Method or Constructor object corresponding to the target method or constructor, respectively.
    final <T> T
    proceed(Object... replacementArguments)
    Allows execution to proceed into the real implementation of the target method/constructor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Invocation

      protected Invocation(@Nullable Object invokedInstance, @NonNull Object[] invokedArguments, @org.checkerframework.checker.index.qual.NonNegative int invocationCount)
      For internal use only.
      Parameters:
      invokedInstance - the invoked instance
      invokedArguments - the invoked arguments
      invocationCount - the invocation count
  • Method Details

    • getInvokedInstance

      @Nullable public final <T> T getInvokedInstance()
      Returns the instance on which the current invocation was made, or null for a static method invocation.
      Type Parameters:
      T - the generic type
      Returns:
      the invoked instance
    • getInvokedMember

      @NonNull public final <M extends Member> M getInvokedMember()
      Returns the Method or Constructor object corresponding to the target method or constructor, respectively.
      Type Parameters:
      M - the generic type
      Returns:
      the invoked member
    • getInvokedArguments

      @NonNull public final Object[] getInvokedArguments()
      Returns the actual argument values passed in the invocation to the target method/constructor.
      Returns:
      the invoked arguments
    • getInvocationCount

      public final @org.checkerframework.checker.index.qual.NonNegative int getInvocationCount()
      Returns the current invocation count. The first invocation starts at 1 (one).
      Returns:
      the invocation count
    • getInvocationIndex

      public final int getInvocationIndex()
      Returns the index for the current invocation. The first invocation starts at 0 (zero). Note that this is equivalent to getInvocationCount() - 1.
      Returns:
      the invocation index
    • proceed

      @Nullable public final <T> T proceed(@Nullable Object... replacementArguments)
      Allows execution to proceed into the real implementation of the target method/constructor.

      In the case of a method, the real implementation is executed with the argument values originally received or explicitly given as replacement. Whatever comes out (either a return value or a thrown exception/error) becomes the result for this execution of the method.

      In the case of a constructor, the real constructor implementation code which comes after the necessary call to "super" is executed, using the original argument values; replacement arguments are not supported. If the execution of said code throws an exception or error, it is propagated out to the caller of the target constructor. Contrary to proceeding into a method, it's not possible to actually execute test code inside the delegate or fake method after proceeding into the real constructor, nor to proceed into it more than once.

      Type Parameters:
      T - the return type of the target method
      Parameters:
      replacementArguments - the argument values to be passed to the real method, as replacement for the values received by the delegate or fake method; if those received values should be passed without replacement, then this method should be called with no values
      Returns:
      the same value returned by the target method, if any
      Throws:
      UnsupportedOperationException - if attempting to proceed into a target method which does not belong to an injectable mocked type nor to a partially mocked object, into a native method, or into an interface or abstract method
      See Also: