/** * Handle condition evaluation results each time evaluation of a condition occurs. Works only with a Hamcrest matcher-based condition. * * @param conditionEvaluationListener the condition evaluation listener * @return the condition factory */ public ConditionFactory conditionEvaluationListener(ConditionEvaluationListener conditionEvaluationListener) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Await forever until the condition is satisfied. Caution: You can block * subsequent tests and the entire build can hang indefinitely, it's * recommended to always use a timeout. * * @return the condition factory */ public ConditionFactory forever() { return new ConditionFactory(alias, AtMostWaitConstraint.FOREVER, pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Instruct Awaitility to catch uncaught exceptions from other threads. This * is useful in multi-threaded systems when you want your test to fail * regardless of which thread throwing the exception. Default is * <code>true</code>. * * @return the condition factory */ public ConditionFactory catchUncaughtExceptions() { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, true, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Catching uncaught exceptions in other threads. This will make the await * statement fail even if exceptions occur in other threads. This is the * default behavior. * * @return the condition factory */ public static ConditionFactory catchUncaughtExceptions() { return new ConditionFactory(null, defaultWaitConstraint, defaultPollInterval, defaultPollDelay, defaultCatchUncaughtExceptions, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }
/** * Don't catch uncaught exceptions in other threads. This will <i>not</i> * make the await statement fail if exceptions occur in other threads. * * @return the condition factory */ public ConditionFactory dontCatchUncaughtExceptions() { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, false, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Don't catch uncaught exceptions in other threads. This will <i>not</i> * make the await statement fail if exceptions occur in other threads. * * @return the condition factory */ public static ConditionFactory dontCatchUncaughtExceptions() { return new ConditionFactory(null, defaultWaitConstraint, defaultPollInterval, defaultPollDelay, false, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }
/** * Set the alias * * @param alias alias * @return the condition factory * @see org.awaitility.Awaitility#await(String) */ public ConditionFactory alias(String alias) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Await for an asynchronous operation and give this await instance a * particular name. This is useful in cases when you have several await * statements in one test and you want to know which one that fails (the * alias will be shown if a timeout exception occurs). * * @param alias the alias * @return the condition factory */ public ConditionFactory await(String alias) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Start building a named await statement. This is useful is cases when you * have several awaits in your test and you need to tell them apart. If a * named await timeout's the <code>alias</code> will be displayed indicating * which await statement that failed. * * @param alias the alias that will be shown if the await timeouts. * @return the condition factory */ public static ConditionFactory await(String alias) { return new ConditionFactory(alias, defaultWaitConstraint, defaultPollInterval, defaultPollDelay, defaultCatchUncaughtExceptions, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }
/** * Start constructing an await statement with some settings. E.g. * <p> * <pre> * with().pollInterval(20, MILLISECONDS).await().until(somethingHappens()); * </pre> * * @return the condition factory */ public static ConditionFactory with() { return new ConditionFactory(null, defaultWaitConstraint, defaultPollInterval, defaultPollDelay, defaultCatchUncaughtExceptions, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }
/** * Start constructing an await statement given some settings. E.g. * <p> * <pre> * given().pollInterval(20, MILLISECONDS).then().await().until(somethingHappens()); * </pre> * * @return the condition factory */ public static ConditionFactory given() { return new ConditionFactory(null, defaultWaitConstraint, defaultPollInterval, defaultPollDelay, defaultCatchUncaughtExceptions, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }
/** * Specify the delay that will be used before Awaitility starts polling for * the result the first time. If you don't specify a poll delay explicitly * it'll be the same as the poll interval. * * @param pollDelay the poll delay * @return the condition factory */ public ConditionFactory pollDelay(Duration pollDelay) { if (pollDelay == null) { throw new IllegalArgumentException("pollDelay cannot be null"); } return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Await at most <code>timeout</code> before throwing a timeout exception. * * @param timeout the timeout * @return the condition factory */ public ConditionFactory atMost(Duration timeout) { return new ConditionFactory(alias, timeoutConstraint.withMaxWaitTime(timeout), pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * An alternative to using {@link #await()} if you want to specify a timeout * directly. * * @param timeout the timeout * @return the condition factory */ public static ConditionFactory waitAtMost(Duration timeout) { return new ConditionFactory(null, defaultWaitConstraint.withMaxWaitTime(timeout), defaultPollInterval, defaultPollDelay, defaultCatchUncaughtExceptions, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }
/** * Condition has to be evaluated not earlier than <code>timeout</code> before throwing a timeout exception. * * @param timeout the timeout * @return the condition factory */ public ConditionFactory atLeast(Duration timeout) { return new ConditionFactory(alias, timeoutConstraint.withMinWaitTime(timeout), pollInterval, pollDelay, catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
public ConditionFactory pollInterval(PollInterval pollInterval) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, definePollDelay(pollDelay, pollInterval), catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied <code>predicate</code>. * Exceptions will be treated as evaluating to * <code>false</code>. This is useful in situations where the evaluated conditions may temporarily throw exceptions. * * @return the condition factory. */ public ConditionFactory ignoreExceptionsMatching(Predicate<? super Throwable> predicate) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, catchUncaughtExceptions, new PredicateExceptionIgnorer(predicate), conditionEvaluationListener, executorLifecycle); }
/** * Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied Hamcrest matcher. * Exceptions will be treated as evaluating to * <code>false</code>. This is useful in situations where the evaluated conditions may temporarily throw exceptions. * * @return the condition factory. */ public ConditionFactory ignoreExceptionsMatching(Matcher<? super Throwable> matcher) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, catchUncaughtExceptions, new HamcrestExceptionIgnorer(matcher), conditionEvaluationListener, executorLifecycle); }
/** * Specify the delay that will be used before Awaitility starts polling for * the result the first time. If you don't specify a poll delay explicitly * it'll be the same as the poll interval. * * @param delay the delay * @param unit the unit * @return the condition factory */ public ConditionFactory pollDelay(long delay, TimeUnit unit) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, new Duration(delay, unit), catchUncaughtExceptions, exceptionsIgnorer, conditionEvaluationListener, executorLifecycle); }
/** * An alternative to using {@link #await()} if you want to specify a timeout * directly. * * @param value the value * @param unit the unit * @return the condition factory */ public static ConditionFactory waitAtMost(long value, TimeUnit unit) { return new ConditionFactory(null, defaultWaitConstraint.withMaxWaitTime(new Duration(value, unit)), defaultPollInterval, defaultPollDelay, defaultCatchUncaughtExceptions, defaultExceptionIgnorer, defaultConditionEvaluationListener, defaultExecutorLifecycle); }