Class LambdaAnswer<T>

  • Type Parameters:
    T - the return type.
    All Implemented Interfaces:
    java.io.Serializable, org.mockito.stubbing.Answer<java.lang.Object>

    public class LambdaAnswer<T>
    extends org.mockito.internal.stubbing.defaultanswers.ForwardsInvocations
    An Answer to optionally call the real method and allow returning a custom result. Captures any exceptions thrown.
    Since:
    1.6
    Author:
    Gary Russell
    See Also:
    Serialized Form
    • Constructor Detail

      • LambdaAnswer

        public LambdaAnswer​(boolean callRealMethod,
                            LambdaAnswer.ValueToReturn<T> callback,
                            @Nullable
                            java.lang.Object delegate)
        Construct an instance with the provided properties. Use the test harness to get an instance with the proper delegate.
        Parameters:
        callRealMethod - true to call the real method.
        callback - the call back to receive the result.
        delegate - the delegate.
    • Method Detail

      • answer

        public T answer​(org.mockito.invocation.InvocationOnMock invocation)
                 throws java.lang.Throwable
        Specified by:
        answer in interface org.mockito.stubbing.Answer<T>
        Overrides:
        answer in class org.mockito.internal.stubbing.defaultanswers.ForwardsInvocations
        Throws:
        java.lang.Throwable
      • getExceptions

        public java.util.Collection<java.lang.Exception> getExceptions()
        Return the exceptions thrown, if any.
        Returns:
        the exceptions.
        Since:
        2.2.3