Class ConditionFactory

java.lang.Object
org.awaitility.core.ConditionFactory

public class ConditionFactory extends Object
A factory for creating Condition objects. It's not recommended instantiating this class directly.
  • Field Details

    • timeoutConstraint

      private final WaitConstraint timeoutConstraint
      Timing constraint.
    • pollInterval

      private final PollInterval pollInterval
      The poll interval.
    • catchUncaughtExceptions

      private final boolean catchUncaughtExceptions
      The catch uncaught exceptions.
    • exceptionsIgnorer

      private final ExceptionIgnorer exceptionsIgnorer
      The ignore exceptions.
    • alias

      private final String alias
      The alias.
    • pollDelay

      private final Duration pollDelay
      The poll delay.
    • conditionEvaluationListener

      private final ConditionEvaluationListener conditionEvaluationListener
      The condition evaluation listener
    • executorLifecycle

      private final ExecutorLifecycle executorLifecycle
      The executor lifecycle
    • failFastCondition

      private final FailFastCondition failFastCondition
      If this condition if ever false, indicates our condition will never be true.
  • Constructor Details

    • ConditionFactory

      public ConditionFactory(String alias, WaitConstraint timeoutConstraint, PollInterval pollInterval, Duration pollDelay, boolean catchUncaughtExceptions, ExceptionIgnorer exceptionsIgnorer, ConditionEvaluationListener conditionEvaluationListener, ExecutorLifecycle executorLifecycle, FailFastCondition failFastCondition)
      Instantiates a new condition factory.
      Parameters:
      alias - the alias
      timeoutConstraint - the timeout constraint
      pollInterval - the poll interval
      pollDelay - The poll delay
      catchUncaughtExceptions - the catch uncaught exceptions
      exceptionsIgnorer - Determine which exceptions that should ignored
      conditionEvaluationListener - Determine which exceptions that should ignored
      executorLifecycle - The executor service and the lifecycle of the executor service that'll be used to evaluate the condition during polling
      failFastCondition - If this condition if ever false, indicates our condition will never be true.
  • Method Details

    • conditionEvaluationListener

      public ConditionFactory conditionEvaluationListener(ConditionEvaluationListener conditionEvaluationListener)
      Handle condition evaluation results each time evaluation of a condition occurs. Works only with a Hamcrest matcher-based condition.
      Parameters:
      conditionEvaluationListener - the condition evaluation listener
      Returns:
      the condition factory
    • logging

      public ConditionFactory logging()
      Logging condition evaluation results each time evaluation of a condition occurs to System.out.
      Returns:
      the condition factory
    • logging

      public ConditionFactory logging(Consumer<String> logPrinter)
      Logging condition evaluation results each time evaluation of a condition occurs to chosen consumer.
      Returns:
      the condition factory
    • 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
    • during

      public ConditionFactory during(Duration timeout)
      Await at the predicate holds during at least timeout
      Parameters:
      timeout - the timeout
      Returns:
      the condition factory
    • during

      public ConditionFactory during(long timeout, TimeUnit unit)
      Await at the predicate holds during at least timeout
      Parameters:
      timeout - the timeout
      unit - the unit
      Returns:
      the condition factory
    • alias

      public ConditionFactory alias(String alias)
      Set the alias
      Parameters:
      alias - alias
      Returns:
      the condition factory
      See Also:
    • atLeast

      public ConditionFactory atLeast(Duration timeout)
      Condition has to be evaluated not earlier than timeout before throwing a timeout exception.
      Parameters:
      timeout - the timeout
      Returns:
      the condition factory
    • atLeast

      public ConditionFactory atLeast(long timeout, TimeUnit unit)
      Condition has to be evaluated not earlier than timeout before throwing a timeout exception.
      Parameters:
      timeout - the timeout
      unit - the unit
      Returns:
      the condition factory
    • between

      public ConditionFactory between(Duration atLeast, Duration atMost)
      Specifies the duration window which has to be satisfied during operation execution. In case operation is executed before atLeast or after atMost timeout exception is thrown.
      Parameters:
      atLeast - lower part of execution window
      atMost - upper part of execution window
      Returns:
      the condition factory
    • between

      public ConditionFactory between(long atLeastDuration, TimeUnit atLeastTimeUnit, long atMostDuration, TimeUnit atMostTimeUnit)
      Specifies the duration window which has to be satisfied during operation execution. In case operation is executed before atLeastDuration or after atMostDuration timeout exception is thrown.
      Parameters:
      atLeastDuration - lower part of execution window
      atMostDuration - upper part of execution window
      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 (if using a FixedPollInterval) unless it's specified explicitly using pollDelay(Duration), pollDelay(long, TimeUnit) or pollDelay(java.time.Duration).

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

      public ConditionFactory timeout(long timeout, 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, 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, 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, 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 pollDelay(java.time.Duration) , or ConditionFactory#andWithPollDelay(long, TimeUnit)}. This is the same as creating a FixedPollInterval.
      Parameters:
      pollInterval - the poll interval
      unit - the unit
      Returns:
      the condition factory
      See Also:
    • pollInterval

      public ConditionFactory pollInterval(PollInterval pollInterval)
    • 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
    • ignoreExceptionsInstanceOf

      public ConditionFactory ignoreExceptionsInstanceOf(Class<? extends Throwable> exceptionType)
      Instruct Awaitility to ignore exceptions instance of the supplied exceptionType type. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.

      If you want to ignore a specific exceptionType then use ignoreException(Class)

      Parameters:
      exceptionType - The exception type (hierarchy) to ignore
      Returns:
      the condition factory
    • ignoreException

      public ConditionFactory ignoreException(Class<? extends Throwable> exceptionType)
      Instruct Awaitility to ignore a specific exception and no subclasses of this exception. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.

      If you want to ignore a subtypes of this exception then use ignoreExceptionsInstanceOf(Class)}

      Parameters:
      exceptionType - The exception type to ignore
      Returns:
      the condition factory
    • ignoreExceptions

      public ConditionFactory ignoreExceptions()
      Instruct Awaitility to ignore all exceptions that occur during evaluation. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.
      Returns:
      the condition factory.
    • ignoreNoExceptions

      public ConditionFactory ignoreNoExceptions()
      Instruct Awaitility to not ignore any exceptions that occur during evaluation. This is only useful if Awaitility is configured to ignore exceptions by default but you want to have a different behavior for a single test case.
      Returns:
      the condition factory.
    • ignoreExceptionsMatching

      public ConditionFactory ignoreExceptionsMatching(org.hamcrest.Matcher<? super Throwable> matcher)
      Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied Hamcrest matcher. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.
      Returns:
      the condition factory.
    • ignoreExceptionsMatching

      public ConditionFactory ignoreExceptionsMatching(Predicate<? super Throwable> predicate)
      Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied predicate. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.
      Returns:
      the condition factory.
    • await

      public ConditionFactory await()
      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
    • await

      public ConditionFactory await(String alias)
      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
    • and

      public ConditionFactory and()
      A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
      Returns:
      the condition factory
    • with

      public ConditionFactory with()
      A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
      Returns:
      the condition factory
    • then

      public ConditionFactory then()
      A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
      Returns:
      the condition factory
    • given

      public ConditionFactory given()
      A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
      Returns:
      the condition factory
    • 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
    • pollExecutorService

      public ConditionFactory pollExecutorService(ExecutorService executorService)
      Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility. Note that the executor service must be shutdown manually!

      This is an advanced feature and it should only be used sparingly.

      Parameters:
      executorService - The executor service that Awaitility will use when polling condition evaluations
      Returns:
      the condition factory
    • pollThread

      public ConditionFactory pollThread(Function<Runnable,Thread> threadSupplier)
      Specify a thread supplier whose thread will be used to evaluate the poll condition in Awaitility. The supplier will be called only once and the thread it returns will be reused during all condition evaluations. This is an advanced feature and it should only be used sparingly.
      Parameters:
      threadSupplier - A supplier of the thread that Awaitility will use when polling
      Returns:
      the condition factory
    • pollInSameThread

      public ConditionFactory pollInSameThread()
      Instructs Awaitility to execute the polling of the condition from the same as the test. This is an advanced feature and you should be careful when combining this with conditions that wait forever (or a long time) since Awaitility cannot interrupt the thread when it's using the same thread as the test. For safety you should always combine tests using this feature with a test framework specific timeout, for example in JUnit:
      Returns:
      the condition factory
    • failFast

      public ConditionFactory failFast(Callable<Boolean> failFastCondition)
      If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately. Throws a TerminalFailureException if fail fast condition evaluates to true. If you want to specify a more descriptive error message then use failFast(String, Callable).
      Parameters:
      failFastCondition - The terminal failure condition
      Returns:
      the condition factory
      See Also:
    • failFast

      public ConditionFactory failFast(String failFastFailureReason, Callable<Boolean> failFastCondition)
      If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately. Throws a TerminalFailureException if fail fast condition evaluates to true.
      Parameters:
      failFastFailureReason - A descriptive reason why the fail fast condition has failed, will be included in the TerminalFailureException thrown if failFastCondition evaluates to true.
      failFastCondition - The terminal failure condition
      Returns:
      the condition factory
    • failFast

      public ConditionFactory failFast(ThrowingRunnable failFastAssertion)
      If the supplied failFastAssertion ever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately. This allows you to use a more descriptive error message of why the fail-fast condition failed by doing e.g.:
       Workflow workflow = ..
       await()
           .atMost(1, MINUTES)
           .failFast(() ->  assertThat(workflow.get("phase")).describedAs("Workflow failed. Last known state:\n" + workflow.toPrettyString()).isNotEqualTo("Failed");
           .untilAsserted(...);
       
      Parameters:
      failFastAssertion - The terminal failure assertion
      Returns:
      the condition factory
      See Also:
    • failFast

      public ConditionFactory failFast(String failFastFailureReason, ThrowingRunnable failFastAssertion)
      If the supplied failFastAssertion ever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately. This allows you to use a more descriptive error message of why the fail-fast condition failed by doing e.g.:
       Workflow workflow = ..
       await()
           .atMost(1, MINUTES)
           .failFast("workflow failed", () ->  assertThat(workflow.get("phase")).describedAs("Workflow failed. Last known state:\n" + workflow.toPrettyString()).isNotEqualTo("Failed");
           .untilAsserted(...);
       
      Parameters:
      failFastFailureReason - A descriptive reason why the fail fast condition has failed, will be included in the TerminalFailureException thrown if failFastAssertion throws an exception.
      failFastAssertion - The terminal failure assertion
      Returns:
      the condition factory
      See Also:
    • until

      public <T> T until(Callable<T> supplier, org.hamcrest.Matcher<? super T> matcher)
      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() {
                              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.
      Returns:
      a T object.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • until

      public <T> T until(Callable<T> supplier, Predicate<? super T> predicate)
      Wait until the given supplier matches the supplied predicate. For example:
       await().until(myRepository::count, cnt -> cnt == 2);
       
      Type Parameters:
      T - the generic type
      Parameters:
      supplier - The supplier that returns the object that will be evaluated by the predicate.
      predicate - The predicate that must match
      Returns:
      a T object.
      Since:
      3.1.1
    • untilAsserted

      public void untilAsserted(ThrowingRunnable assertion)
      Await until a Runnable supplier execution passes (ends without throwing an exception). E.g. with Java 8:

       

       await().untilAsserted(() -> Assertions.assertThat(personRepository.size()).isEqualTo(6));
       
      or
       await().untilAsserted(() -> assertEquals(6, personRepository.size()));
       

       

      This method is intended to benefit from lambda expressions introduced in Java 8. It allows to use standard AssertJ/FEST Assert assertions (by the way also standard JUnit/TestNG assertions) to test asynchronous calls and systems.

       

      AssertionError instances thrown by the supplier are treated as an assertion failure and proper error message is propagated on timeout. Other exceptions are rethrown immediately as an execution errors.

       

      While technically it is completely valid to use plain Runnable class in Java 7 code, the resulting expression is very verbose and can decrease the readability of the test case, e.g.

       

       await().untilAsserted(new Runnable() {
           public void run() {
               Assertions.assertThat(personRepository.size()).isEqualTo(6);
           }
       });
       

       

      NOTE:
      Be VERY careful so that you're not using this method incorrectly in languages (like Kotlin and Groovy) that doesn't disambiguate between a ThrowingRunnable that doesn't return anything (void) and Callable that returns a value. For example in Kotlin you can do like this:

       

       await().untilAsserted { true == false }
       
      and the compiler won't complain with an error (as is the case in Java). If you were to execute this test in Kotlin it'll pass!
      Parameters:
      assertion - the supplier that is responsible for executing the assertion and throwing AssertionError on failure.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
      Since:
      1.6.0
    • untilAsserted

      public <T> void untilAsserted(Callable<T> supplier, Consumer<? super T> assertConsumer)
      Await until a callable returns a value that when passed to a Consumer ends without throwing an exception. E.g. with Java 8:

       

       public class MyBean {
      
           public String myFunction() {
                // Imagine stuff being executed in asynchrinously here and the result of this
                // operation is a string called "my value"
               return "my value"
           }
       }
      
       // Then in your test you can wait for the "myFunction" to return "my value"
       await().untilAsserted(myBean::myFunction, value ->  Assertions.assertThat(value).isEqualTo("my value"));
       
      Parameters:
      supplier - the supplier that is responsible for executing the assertion and throwing AssertionError on failure.
      assertConsumer - The consumer that will assert that the supplied value is correct, or throw an exception.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
      Since:
      4.3.2
    • untilAtomic

      public Integer untilAtomic(AtomicInteger atomic, org.hamcrest.Matcher<? super Integer> matcher)
      Await until a Atomic variable has a value matching the specified Matcher. E.g.

       

       await().untilAtomic(myAtomic, is(greaterThan(2)));
       
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Returns:
      a Integer object.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public void untilAtomic(AtomicInteger atomic, Consumer<? super Integer> matcher)
      Await until a Atomic integer is asserted by the matcher consumer E.g.

       

       await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123));
       
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public Long untilAtomic(AtomicLong atomic, org.hamcrest.Matcher<? super Long> matcher)
      Await until a Atomic variable has a value matching the specified Matcher. E.g.

       

       await().untilAtomic(myAtomic, is(greaterThan(2)));
       
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Returns:
      a Long object.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public void untilAtomic(AtomicLong atomic, Consumer<? super Long> matcher)
      Await until a Atomic long is asserted by the matcher consumer E.g.

       

       await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123L));
       
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public void untilAtomic(AtomicBoolean atomic, org.hamcrest.Matcher<? super Boolean> matcher)
      Await until a Atomic variable has a value matching the specified Matcher. E.g.

       

       await().untilAtomic(myAtomic, is(greaterThan(2)));
       
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public void untilAtomic(AtomicBoolean atomic, Consumer<? super Boolean> matcher)
      Await until a AtomicBoolean is asserted by the matcher consumer E.g.

       

       await().untilAtomic(myAtomicBoolean, value -> Assertions.assertThat(value).isTrue());
       
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The consumer that validates that the atomic boolean value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilTrue

      public void untilTrue(AtomicBoolean atomic)
      Await until a Atomic boolean becomes true.
      Parameters:
      atomic - the atomic variable
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilFalse

      public void untilFalse(AtomicBoolean atomic)
      Await until a Atomic boolean becomes false.
      Parameters:
      atomic - the atomic variable
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAdder

      public void untilAdder(LongAdder adder, org.hamcrest.Matcher<? super Long> matcher)
      Await until a LongAdder has a value matching the specified Matcher. E.g.

       

       await().untilAdder(myLongAdder, is(greaterThan(2L)));
       
      Parameters:
      adder - the LongAdder variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAdder

      public void untilAdder(LongAdder adder, Consumer<? super Long> matcher)
      Await until a LongAdder is asserted by the matcher consumer E.g.

       

       await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
       
      Parameters:
      adder - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAdder

      public void untilAdder(DoubleAdder adder, org.hamcrest.Matcher<? super Double> matcher)
      Await until a DoubleAdder has a value matching the specified Matcher. E.g.

       

       await().untilAdder(myDoubleAdder, is(greaterThan(2.0d)));
       
      Parameters:
      adder - the DoubleAdder variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAdder

      public void untilAdder(DoubleAdder adder, Consumer<? super Double> matcher)
      Await until a DoubleAdder is asserted by the matcher consumer E.g.

       

       await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
       
      Parameters:
      adder - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAccumulator

      public void untilAccumulator(LongAccumulator accumulator, org.hamcrest.Matcher<? super Long> matcher)
      Await until a LongAccumulator has a value matching the specified Matcher. E.g.

       

       await().untilAccumulator(myLongAccumulator, is(greaterThan(2L)));
       
      Parameters:
      accumulator - the LongAccumulator variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAccumulator

      public void untilAccumulator(LongAccumulator accumulator, Consumer<? super Long> matcher)
      Await until a LongAccumulator is asserted by the matcher consumer E.g.

       

       await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
       
      Parameters:
      accumulator - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAccumulator

      public void untilAccumulator(DoubleAccumulator accumulator, org.hamcrest.Matcher<? super Double> matcher)
      Await until a DoubleAccumulator has a value matching the specified Matcher. E.g.

       

       await().untilAccumulator(myDoubleAccumulator, is(greaterThan(2.0d)));
       
      Parameters:
      accumulator - the DoubleAccumulator variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAccumulator

      public void untilAccumulator(DoubleAccumulator accumulator, Consumer<? super Double> matcher)
      Await until a DoubleAccumulator is asserted by the matcher consumer E.g.

       

       await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
       
      Parameters:
      accumulator - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public <V> V untilAtomic(AtomicReference<V> atomic, org.hamcrest.Matcher<? super V> matcher)
      Await until a Atomic variable has a value matching the specified Matcher. E.g.

       

       await().untilAtomic(myAtomic, is(greaterThan(2)));
       
      Type Parameters:
      V - a V object.
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
      Returns:
      a V object.
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • untilAtomic

      public <V> void untilAtomic(AtomicReference<V> atomic, Consumer<? super V> matcher)
      Await until a Atomic variable is asserted by the matcher consumer E.g.

       

       await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo("something"));
       
      Type Parameters:
      V - a V object.
      Parameters:
      atomic - the atomic variable
      matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • until

      public void until(Callable<Boolean> conditionEvaluator)
      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() {
                              return personRepository.size() == 3;
              }
          };
       }
       
      Parameters:
      conditionEvaluator - the condition evaluator
      Throws:
      ConditionTimeoutException - If condition was not fulfilled within the given time period.
    • generateConditionSettings

      private ConditionSettings generateConditionSettings()
    • until

      private <T> T until(Condition<T> condition)
    • definePollDelay

      private Duration definePollDelay(Duration pollDelay, PollInterval pollInterval)
      Ensures backward compatibility (especially that poll delay is the same as poll interval for fixed poll interval). It also make sure that poll delay is Duration.ZERO for all other poll intervals if poll delay was not explicitly defined. If poll delay was explicitly defined the it will just be returned.
      Parameters:
      pollDelay - The poll delay
      pollInterval - The chosen (or default) poll interval
      Returns:
      The poll delay to use