Class VerificationOverTimeImpl

  • All Implemented Interfaces:
    VerificationMode

    public class VerificationOverTimeImpl
    extends java.lang.Object
    implements VerificationMode
    Verifies that another verification mode (the delegate) is satisfied within a certain timeframe (before timeoutMillis has passed, measured from the call to verify()), and either returns immediately once it does, or waits until it is definitely satisfied once the full time has passed.
    • Field Detail

      • pollingPeriodMillis

        private final long pollingPeriodMillis
      • returnOnSuccess

        private final boolean returnOnSuccess
      • timer

        private final Timer timer
    • Constructor Detail

      • VerificationOverTimeImpl

        public VerificationOverTimeImpl​(long pollingPeriodMillis,
                                        long durationMillis,
                                        VerificationMode delegate,
                                        boolean returnOnSuccess)
        Create this verification mode, to be used to verify invocation ongoing data later.
        Parameters:
        pollingPeriodMillis - The frequency to poll delegate.verify(), to check whether the delegate has been satisfied
        durationMillis - The max time to wait (in millis) for the delegate verification mode to be satisfied
        delegate - The verification mode to delegate overall success or failure to
        returnOnSuccess - Whether to immediately return successfully once the delegate is satisfied (as in VerificationWithTimeout, or to only return once the delegate is satisfied and the full duration has passed (as in VerificationAfterDelay).
      • VerificationOverTimeImpl

        public VerificationOverTimeImpl​(long pollingPeriodMillis,
                                        VerificationMode delegate,
                                        boolean returnOnSuccess,
                                        Timer timer)
        Create this verification mode, to be used to verify invocation ongoing data later.
        Parameters:
        pollingPeriodMillis - The frequency to poll delegate.verify(), to check whether the delegate has been satisfied
        delegate - The verification mode to delegate overall success or failure to
        returnOnSuccess - Whether to immediately return successfully once the delegate is satisfied (as in VerificationWithTimeout, or to only return once the delegate is satisfied and the full duration has passed (as in VerificationAfterDelay).
        timer - Checker of whether the duration of the verification is still acceptable
    • Method Detail

      • verify

        public void verify​(VerificationData data)
        Verify the given ongoing verification data, and confirm that it satisfies the delegate verification mode before the full duration has passed. In practice, this polls the delegate verification mode until it is satisfied. If it is not satisfied once the full duration has passed, the last error returned by the delegate verification mode will be thrown here in turn. This may be thrown early if the delegate is unsatisfied and the verification mode is known to never recover from this situation (e.g. AtMost). If it is satisfied before the full duration has passed, behaviour is dependent on the returnOnSuccess parameter given in the constructor. If true, this verification mode is immediately satisfied once the delegate is. If false, this verification mode is not satisfied until the delegate is satisfied and the full time has passed.
        Specified by:
        verify in interface VerificationMode
        Throws:
        MockitoAssertionError - if the delegate verification mode does not succeed before the timeout
      • handleVerifyException

        private java.lang.AssertionError handleVerifyException​(java.lang.AssertionError e)
      • canRecoverFromFailure

        protected boolean canRecoverFromFailure​(VerificationMode verificationMode)
      • sleep

        private void sleep​(long sleep)
      • isReturnOnSuccess

        public boolean isReturnOnSuccess()
      • getPollingPeriodMillis

        public long getPollingPeriodMillis()
      • getTimer

        public Timer getTimer()