Interface InvocationOnMock

  • All Superinterfaces:
    java.io.Serializable
    All Known Subinterfaces:
    Invocation
    All Known Implementing Classes:
    InterceptedInvocation

    @NotExtensible
    public interface InvocationOnMock
    extends java.io.Serializable
    An invocation on a mock.

    A placeholder for mock, the method that was called and the arguments that were passed.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.Object callRealMethod()
      calls real method
      <T> T getArgument​(int index)
      Returns casted argument at the given index.
      <T> T getArgument​(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.lang.reflect.Method getMethod()
      returns the method
      java.lang.Object getMock()
      returns the mock object
    • Method Detail

      • getMock

        java.lang.Object getMock()
        returns the mock object
        Returns:
        mock object
      • getMethod

        java.lang.reflect.Method getMethod()
        returns the method
        Returns:
        method
      • getArguments

        java.lang.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 form getArguments(). This method is preferred over getArgument(int, Class) for readability. Please read the documentation of getArgument(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

        <T> T getArgument​(int index,
                          java.lang.Class<T> clazz)
        Returns casted argument at the given index. This method is analogous to getArgument(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:
        1. You want to directly invoke a method on the result of getArgument(int).
        2. You want to directly pass the result of the invocation into a function that accepts a generic parameter.
        If you prefer to use 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 index
        clazz - class to cast the argument to
        Returns:
        casted argument at the given index
      • callRealMethod

        java.lang.Object callRealMethod()
                                 throws java.lang.Throwable
        calls real method

        Warning: depending on the real implementation it might throw exceptions

        Returns:
        whatever the real method returns / throws
        Throws:
        java.lang.Throwable - in case real method throws