Class LatchCountDownAndCallRealMethodAnswer

  • All Implemented Interfaces:
    java.io.Serializable, org.mockito.stubbing.Answer<java.lang.Object>

    public class LatchCountDownAndCallRealMethodAnswer
    extends org.mockito.internal.stubbing.defaultanswers.ForwardsInvocations
    An Answer for void returning methods that calls the real method and counts down a latch. Captures any exceptions thrown.
    Since:
    1.6
    Author:
    Gary Russell
    See Also:
    Serialized Form
    • Constructor Detail

      • LatchCountDownAndCallRealMethodAnswer

        @Deprecated
        public LatchCountDownAndCallRealMethodAnswer​(int count)
        Get an instance with no delegate.
        Parameters:
        count - to set in a CountDownLatch.
      • LatchCountDownAndCallRealMethodAnswer

        public LatchCountDownAndCallRealMethodAnswer​(int count,
                                                     @Nullable
                                                     java.lang.Object delegate)
        Get an instance with the provided properties. Use the test harness to get an instance with the proper delegate.
        Parameters:
        count - the count.
        delegate - the delegate.
        Since:
        2.1.16
    • Method Detail

      • answer

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

        public boolean await​(int timeout)
                      throws java.lang.InterruptedException
        Wait for the latch to count down.
        Parameters:
        timeout - the timeout in seconds.
        Returns:
        the result of awaiting on the latch; true if counted down.
        Throws:
        java.lang.InterruptedException - if the thread is interrupted.
        Since:
        2.1.16
      • getLatch

        public java.util.concurrent.CountDownLatch getLatch()
      • getExceptions

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