Class EventualCondition


  • public class EventualCondition
    extends java.lang.Object
    A test condition that is evaluated repeatedly during a reasonable period of time. It's intended to assert asynchronous changes. Default evaluation period is 10 seconds and the condition is evaluated approximately every 500 milliseconds.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static EventualCondition eventualCondition()
      Creates evaluation condition with default evaluation period and interval.
      void expect​(java.lang.Runnable body)
      Evaluates the conditions represented by the code body.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • eventualCondition

        public static EventualCondition eventualCondition()
        Creates evaluation condition with default evaluation period and interval.
        Returns:
        a condition that is evaluated about every 500 milliseconds within 10 seconds period.
      • expect

        public void expect​(java.lang.Runnable body)
        Evaluates the conditions represented by the code body. For example, let's say we have a class Job that changes its state asynchronously. In this case this method can be used like this:
               Job job = new Job
        
               // start the job
               job.start();
        
               // assert the asynchronous condition that the job eventually finishes.
               eventualCondition().expect(() -> assertEquals("finished", job.getState());
         
        Parameters:
        body - a code to evaluate. It should throw an exception when the condition is not met.