Class VerificationOverTimeImpl
- java.lang.Object
-
- org.mockito.internal.verification.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 Summary
Fields Modifier and Type Field Description private VerificationMode
delegate
private long
pollingPeriodMillis
private boolean
returnOnSuccess
private Timer
timer
-
Constructor Summary
Constructors Constructor Description VerificationOverTimeImpl(long pollingPeriodMillis, long durationMillis, VerificationMode delegate, boolean returnOnSuccess)
Create this verification mode, to be used to verify invocation ongoing data later.VerificationOverTimeImpl(long pollingPeriodMillis, VerificationMode delegate, boolean returnOnSuccess, Timer timer)
Create this verification mode, to be used to verify invocation ongoing data later.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canRecoverFromFailure(VerificationMode verificationMode)
VerificationOverTimeImpl
copyWithVerificationMode(VerificationMode verificationMode)
VerificationMode
getDelegate()
long
getPollingPeriodMillis()
Timer
getTimer()
private java.lang.AssertionError
handleVerifyException(java.lang.AssertionError e)
boolean
isReturnOnSuccess()
private void
sleep(long sleep)
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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mockito.verification.VerificationMode
description
-
-
-
-
Field Detail
-
pollingPeriodMillis
private final long pollingPeriodMillis
-
delegate
private final VerificationMode delegate
-
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 satisfieddurationMillis
- The max time to wait (in millis) for the delegate verification mode to be satisfieddelegate
- The verification mode to delegate overall success or failure toreturnOnSuccess
- Whether to immediately return successfully once the delegate is satisfied (as inVerificationWithTimeout
, or to only return once the delegate is satisfied and the full duration has passed (as inVerificationAfterDelay
).
-
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 satisfieddelegate
- The verification mode to delegate overall success or failure toreturnOnSuccess
- Whether to immediately return successfully once the delegate is satisfied (as inVerificationWithTimeout
, or to only return once the delegate is satisfied and the full duration has passed (as inVerificationAfterDelay
).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 interfaceVerificationMode
- 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)
-
copyWithVerificationMode
public VerificationOverTimeImpl copyWithVerificationMode(VerificationMode verificationMode)
-
sleep
private void sleep(long sleep)
-
isReturnOnSuccess
public boolean isReturnOnSuccess()
-
getPollingPeriodMillis
public long getPollingPeriodMillis()
-
getTimer
public Timer getTimer()
-
getDelegate
public VerificationMode getDelegate()
-
-