Class WaitExtensions


  • @Component("tapirWaitExtensions")
    public class WaitExtensions
    extends java.lang.Object
    Provides some convenience methods in order to wait for a certain condition.
    Since:
    2.0.0
    Author:
    Oliver Libutzki <[email protected]>
    • Constructor Summary

      Constructors 
      Constructor Description
      WaitExtensions()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected long calculateWaitTime​(long timeout)
      Calculates the wait time between two attempts.
      boolean waitForCondition​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition)
      Calls waitForCondition(Function0, long) with the configured implicit wait time.
      boolean waitForCondition​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition, long timeout)
      Waits for the condition becoming true.
      <T> T waitForNoException​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
      Calls waitForNoThrowableOfType(Class, Function0) with Exception as throwableType parameter.
      <T> T waitForNoException​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
      Calls waitForNoThrowableOfType(Class, Function0, long) with Exception as throwableType parameter.
      <T> T waitForNoThrowableOfType​(java.lang.Class<? extends java.lang.Throwable> throwableType, org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
      Calls waitForNoThrowableOfType(Class, Function0, long) with the configured implicit wait time.
      <T> T waitForNoThrowableOfType​(java.lang.Class<? extends java.lang.Throwable> throwableType, org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
      Waits for the lambda expression throwing no longer an Throwable which is assignable-compatible with the given throwableType.
      <T> T waitForNotNull​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
      Calls waitForNotNull(Function0, long) with the configured implicit wait time.
      <T> T waitForNotNull​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
      Waits for the lambda expression returning something else than null.
      • Methods inherited from class java.lang.Object

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

      • WaitExtensions

        public WaitExtensions()
    • Method Detail

      • waitForCondition

        public boolean waitForCondition​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition)
        Calls waitForCondition(Function0, long) with the configured implicit wait time. The condition is evaluated at least once.
        Parameters:
        condition - The condition to wait for.
        Returns:
        true if and only if the condition became true before the timeout.
        Since:
        3.0.0
      • waitForNotNull

        public <T> T waitForNotNull​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
        Calls waitForNotNull(Function0, long) with the configured implicit wait time. The executable is executed at least once.
        Type Parameters:
        T - return type of the given executable
        Parameters:
        executable - The lambda expression to wait for.
        Returns:
        The result of the lambda expression once it returns something else than null before the timeout occurs. Otherwise null is returned.
        Since:
        3.0.0
      • waitForNoException

        public <T> T waitForNoException​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
        Calls waitForNoThrowableOfType(Class, Function0) with Exception as throwableType parameter. The executable is executed at least once.
        Type Parameters:
        T - return type of the given executable
        Parameters:
        executable - The lambda expression to wait for.
        Returns:
        The result of the lambda expression once it returns something. Otherwise the last thrown exception is thrown.
        Since:
        2.0.0
      • waitForNoThrowableOfType

        public <T> T waitForNoThrowableOfType​(java.lang.Class<? extends java.lang.Throwable> throwableType,
                                              org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
        Calls waitForNoThrowableOfType(Class, Function0, long) with the configured implicit wait time. The executable is executed at least once.
        Type Parameters:
        T - return type of the given executable
        Parameters:
        throwableType - The throwable type (including subtypes) which should be handled.
        executable - The lambda expression to wait for.
        Returns:
        The result of the lambda expression once it returns something. Otherwise the last thrown exception is thrown.
        Since:
        3.1.0
      • waitForCondition

        public boolean waitForCondition​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition,
                                        long timeout)
        Waits for the condition becoming true. The default implementation waits a quarter of the timeout between each attempt. The condition is evaluated at least once.
        Parameters:
        condition - The condition to wait for.
        timeout - The timeout in milliseconds after which the method returns false.
        Returns:
        true if and only if the condition became true before the timeout.
        Since:
        2.0.0
      • waitForNotNull

        public <T> T waitForNotNull​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable,
                                    long timeout)
        Waits for the lambda expression returning something else than null. The default implementation waits a quarter of the timeout between each attempt. The executable is executed at least once.
        Type Parameters:
        T - return type of the given executable
        Parameters:
        executable - The lambda expression to wait for.
        timeout - The timeout in milliseconds after which the method returns null.
        Returns:
        The result of the lambda expression once it returns something else than null before the timeout occurs. Otherwise null is returned.
        Since:
        2.0.0
      • waitForNoException

        public <T> T waitForNoException​(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable,
                                        long timeout)
        Calls waitForNoThrowableOfType(Class, Function0, long) with Exception as throwableType parameter. The executable is executed at least once.
        Type Parameters:
        T - return type of the given executable
        Parameters:
        executable - The lambda expression to wait for.
        timeout - The timeout in milliseconds after which the method returns null or throws the last exception.
        Returns:
        The result of the lambda expression once it returns something. Otherwise the last thrown exception is thrown.
        Since:
        2.0.0
      • waitForNoThrowableOfType

        public <T> T waitForNoThrowableOfType​(java.lang.Class<? extends java.lang.Throwable> throwableType,
                                              org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable,
                                              long timeout)
        Waits for the lambda expression throwing no longer an Throwable which is assignable-compatible with the given throwableType. The default implementation waits a quarter of the timeout between each attempt. The executable is executed at least once.
        Type Parameters:
        T - return type of the given executable
        Parameters:
        throwableType - The throwable type (including subtypes) which should be handled.
        executable - The lambda expression to wait for.
        timeout - The timeout in milliseconds after which the method returns null or throws the last Throwable.
        Returns:
        The result of the lambda expression once it returns something. Otherwise the last thrown Throwable is thrown.
        Since:
        3.1.0
      • calculateWaitTime

        protected long calculateWaitTime​(long timeout)
        Calculates the wait time between two attempts. This is a quarter of the timeout or at most 200 ms in the default implementation.
        Parameters:
        timeout - The timeout in milliseconds.
        Returns:
        The wait time in milliseconds.