com.jayway.awaitility.core
Class ConditionFactory

java.lang.Object
  extended by com.jayway.awaitility.core.ConditionFactory

public class ConditionFactory
extends java.lang.Object

A factory for creating Condition objects. It's not recommended to instantiate this class directly.


Constructor Summary
ConditionFactory(Duration timeout, Duration pollInterval, Duration pollDelay, boolean catchUncaughtExceptions)
          Instantiates a new condition factory.
ConditionFactory(java.lang.String alias, Duration timeout, Duration pollInterval, Duration pollDelay, boolean catchUncaughtExceptions)
          Instantiates a new condition factory.
 
Method Summary
 ConditionFactory and()
          A method to increase the readability of the Awaitility DSL.
 ConditionFactory atMost(Duration timeout)
          Await at most timeout before throwing a timeout exception.
 ConditionFactory atMost(long timeout, java.util.concurrent.TimeUnit unit)
          Await at most timeout before throwing a timeout exception.
 ConditionFactory await()
          Await for an asynchronous operation.
 ConditionFactory await(java.lang.String alias)
          Await for an asynchronous operation and give this await instance a particular name.
 ConditionFactory catchUncaughtExceptions()
          Instruct Awaitility to catch uncaught exceptions from other threads.
 ConditionFactory dontCatchUncaughtExceptions()
          Don't catch uncaught exceptions in other threads.
 ConditionFactory forever()
          Await forever until the condition is satisfied.
 ConditionFactory given()
          A method to increase the readability of the Awaitility DSL.
 ConditionFactory pollDelay(Duration pollDelay)
          Specify the delay that will be used before Awaitility starts polling for the result the first time.
 ConditionFactory pollDelay(long delay, java.util.concurrent.TimeUnit unit)
          Specify the delay that will be used before Awaitility starts polling for the result the first time.
 ConditionFactory pollInterval(Duration pollInterval)
          Specify the polling interval Awaitility will use for this await statement.
 ConditionFactory pollInterval(long pollInterval, java.util.concurrent.TimeUnit unit)
          Specify the polling interval Awaitility will use for this await statement.
 ConditionFactory then()
          A method to increase the readability of the Awaitility DSL.
 ConditionFactory timeout(Duration timeout)
          Await at most timeout before throwing a timeout exception.
 ConditionFactory timeout(long timeout, java.util.concurrent.TimeUnit unit)
          Await at most timeout before throwing a timeout exception.
<T> void
until(java.util.concurrent.Callable<java.lang.Boolean> conditionEvaluator)
          Await until a Callable returns true.
<T> void
until(java.util.concurrent.Callable<T> supplier, org.hamcrest.Matcher<T> matcher)
          Await until a Callable supplies a value matching the specified Matcher.
<T> void
until(T ignore, org.hamcrest.Matcher<T> matcher)
          Specify the condition that must be met when waiting for a method call.
 ConditionFactory with()
          A method to increase the readability of the Awaitility DSL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConditionFactory

public ConditionFactory(java.lang.String alias,
                        Duration timeout,
                        Duration pollInterval,
                        Duration pollDelay,
                        boolean catchUncaughtExceptions)
Instantiates a new condition factory.

Parameters:
alias - the alias
timeout - the timeout
pollInterval - the poll interval
pollDelay - The poll delay
catchUncaughtExceptions - the catch uncaught exceptions

ConditionFactory

public ConditionFactory(Duration timeout,
                        Duration pollInterval,
                        Duration pollDelay,
                        boolean catchUncaughtExceptions)
Instantiates a new condition factory.

Parameters:
timeout - the timeout
pollInterval - the poll interval
pollDelay - The delay before the polling starts
catchUncaughtExceptions - the catch uncaught exceptions
Method Detail

timeout

public ConditionFactory timeout(Duration timeout)
Await at most timeout before throwing a timeout exception.

Parameters:
timeout - the timeout
Returns:
the condition factory

atMost

public ConditionFactory atMost(Duration timeout)
Await at most timeout before throwing a timeout exception.

Parameters:
timeout - the timeout
Returns:
the condition factory

forever

public ConditionFactory forever()
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.

Returns:
the condition factory

pollInterval

public ConditionFactory pollInterval(Duration pollInterval)
Specify the polling interval Awaitility will use for this await statement. This means the frequency in which the condition is checked for completion.

Note that the poll delay will be automatically set as to the same value as the interval unless it's specified explicitly using pollDelay(Duration), pollDelay(long, TimeUnit) or ConditionFactory#andWithPollDelay(Duration), or ConditionFactory#andWithPollDelay(long, TimeUnit).

Parameters:
pollInterval - the poll interval
Returns:
the condition factory

timeout

public ConditionFactory timeout(long timeout,
                                java.util.concurrent.TimeUnit unit)
Await at most timeout before throwing a timeout exception.

Parameters:
timeout - the timeout
unit - the unit
Returns:
the condition factory

pollDelay

public ConditionFactory pollDelay(long delay,
                                  java.util.concurrent.TimeUnit unit)
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.

Parameters:
delay - the delay
unit - the unit
Returns:
the condition factory

pollDelay

public ConditionFactory pollDelay(Duration pollDelay)
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.

Parameters:
pollDelay - the poll delay
Returns:
the condition factory

atMost

public ConditionFactory atMost(long timeout,
                               java.util.concurrent.TimeUnit unit)
Await at most timeout before throwing a timeout exception.

Parameters:
timeout - the timeout
unit - the unit
Returns:
the condition factory

pollInterval

public ConditionFactory pollInterval(long pollInterval,
                                     java.util.concurrent.TimeUnit unit)
Specify the polling interval Awaitility will use for this await statement. This means the frequency in which the condition is checked for completion.

Note that the poll delay will be automatically set as to the same value as the interval unless it's specified explicitly using pollDelay(Duration), pollDelay(long, TimeUnit) or ConditionFactory#andWithPollDelay(Duration), or ConditionFactory#andWithPollDelay(long, TimeUnit).

Parameters:
pollInterval - the poll interval
unit - the unit
Returns:
the condition factory

catchUncaughtExceptions

public ConditionFactory catchUncaughtExceptions()
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 true.

Returns:
the condition factory

await

public ConditionFactory await()
                       throws java.lang.Exception
Await for an asynchronous operation. This method returns the same ConditionFactory instance and is used only to get a more fluent-like syntax.

Returns:
the condition factory
Throws:
java.lang.Exception - the exception

await

public ConditionFactory await(java.lang.String alias)
                       throws java.lang.Exception
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).

Parameters:
alias - the alias
Returns:
the condition factory
Throws:
java.lang.Exception - the exception

and

public ConditionFactory and()
                     throws java.lang.Exception
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.

Returns:
the condition factory
Throws:
java.lang.Exception - the exception

with

public ConditionFactory with()
                      throws java.lang.Exception
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.

Returns:
the condition factory
Throws:
java.lang.Exception - the exception

then

public ConditionFactory then()
                      throws java.lang.Exception
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.

Returns:
the condition factory
Throws:
java.lang.Exception - the exception

given

public ConditionFactory given()
                       throws java.lang.Exception
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.

Returns:
the condition factory
Throws:
java.lang.Exception - the exception

dontCatchUncaughtExceptions

public ConditionFactory dontCatchUncaughtExceptions()
Don't catch uncaught exceptions in other threads. This will not make the await statement fail if exceptions occur in other threads.

Returns:
the condition factory

until

public <T> void until(T ignore,
                      org.hamcrest.Matcher<T> matcher)
           throws java.lang.Exception
Specify the condition that must be met when waiting for a method call. E.g.
 await().until(callTo(orderService).size(), is(greaterThan(2)));
 

Type Parameters:
T - the generic type
Parameters:
ignore - the return value of the method call
matcher - The condition that must be met when
Throws:
java.lang.Exception - the exception

until

public <T> void until(java.util.concurrent.Callable<T> supplier,
                      org.hamcrest.Matcher<T> matcher)
           throws java.lang.Exception
Await until a Callable supplies a value matching the specified Matcher. E.g.
 await().until(numberOfPersons(), is(greaterThan(2)));
 
where "numberOfPersons()" returns a standard Callable:
 private Callable<Integer> numberOfPersons() {
        return new Callable<Integer>() {
                public Integer call() throws Exception {
                        return personRepository.size();
                }
        };
 }
 
Using a generic Callable as done by using this version of "until" allows you to reuse the "numberOfPersons()" definition in multiple await statements. I.e. you can easily create another await statement (perhaps in a different test case) using e.g.
 await().until(numberOfPersons(), is(equalTo(6)));
 

Type Parameters:
T - the generic type
Parameters:
supplier - the supplier that is responsible for getting the value that should be matched.
matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
Throws:
java.lang.Exception - the exception

until

public <T> void until(java.util.concurrent.Callable<java.lang.Boolean> conditionEvaluator)
           throws java.lang.Exception
Await until a Callable returns true. This is method is not as generic as the other variants of "until" but it allows for a more precise and in some cases even more english-like syntax. E.g.
 await().until(numberOfPersonsIsEqualToThree());
 
where "numberOfPersonsIsEqualToThree()" returns a standard Callable of type Boolean:
 private Callable<Boolean> numberOfPersons() {
        return new Callable<Boolean>() {
                public Boolean call() throws Exception {
                        return personRepository.size() == 3;
                }
        };
 }

Type Parameters:
T - the generic type
Parameters:
conditionEvaluator - the condition evaluator
Throws:
java.lang.Exception - the exception


Copyright © 2010. All Rights Reserved.