Class JavaTest

  • Direct Known Subclasses:
    JavaOSGiTest

    @NonNullByDefault
    public class JavaTest
    extends Object
    JavaTest is an abstract base class for tests which are not necessarily based on OSGi.
    Author:
    Simon Kaufmann - Initial contribution
    • Constructor Detail

      • JavaTest

        public JavaTest()
    • Method Detail

      • waitFor

        protected boolean waitFor​(BooleanSupplier condition)
        Wait until the condition is fulfilled or the timeout is reached.

        This method uses the default timing parameters.

        Parameters:
        condition - the condition to check
        Returns:
        true on success, false on timeout
      • waitFor

        protected boolean waitFor​(BooleanSupplier condition,
                                  long timeout,
                                  long sleepTime)
        Wait until the condition is fulfilled or the timeout is reached.
        Parameters:
        condition - the condition to check
        timeout - timeout
        sleepTime - interval for checking the condition
        Returns:
        true on success, false on timeout
      • waitForAssert

        protected void waitForAssert​(Runnable assertion)
        Wait until the assertion is fulfilled or the timeout is reached.

        This method uses the default timing parameters.

        Parameters:
        assertion - closure that must not have an argument
      • waitForAssert

        protected void waitForAssert​(Runnable assertion,
                                     long timeout,
                                     long sleepTime)
        Wait until the assertion is fulfilled or the timeout is reached.
        Parameters:
        assertion - the logic to execute
        timeout - timeout
        sleepTime - interval for checking the condition
      • waitForAssert

        protected <T> T waitForAssert​(Supplier<T> assertion)
        Wait until the assertion is fulfilled or the timeout is reached.

        This method uses the default timing parameters.

        Parameters:
        assertion - the logic to execute
        Returns:
        the return value of the supplied assertion object's function on success
      • waitForAssert

        protected <T> T waitForAssert​(Supplier<T> assertion,
                                      long timeout,
                                      long sleepTime)
        Wait until the assertion is fulfilled or the timeout is reached.
        Parameters:
        assertion - the logic to execute
        timeout - timeout
        sleepTime - interval for checking the condition
        Returns:
        the return value of the supplied assertion object's function on success
      • waitForAssert

        protected void waitForAssert​(Runnable assertion,
                                     @Nullable Runnable beforeLastCall,
                                     long timeout,
                                     long sleepTime)
        Wait until the assertion is fulfilled or the timeout is reached.
        Parameters:
        assertion - the logic to execute
        beforeLastCall - logic to execute in front of the last call to ${code assertion}
        sleepTime - interval for checking the condition
      • waitForAssert

        protected void waitForAssert​(Runnable assertion,
                                     @Nullable Runnable beforeLastCall,
                                     @Nullable Runnable afterLastCall,
                                     long timeout,
                                     long sleepTime)
        Wait until the assertion is fulfilled or the timeout is reached.
        Parameters:
        assertion - the logic to execute
        beforeLastCall - logic to execute in front of the last call to ${code assertion}
        afterLastCall - logic to execute after the last call to ${code assertion}
        sleepTime - interval for checking the condition
      • giveNull

        protected static <T> T giveNull()
        Useful for testing @NonNull annotated parameters

        This method can be used if you want to check the behavior of a method if you supply null to a non-null marked argument. If you use null directly the compiler will raise an error. Using this method allows you to work around that compiler check by using a null value that is marked as non-null.

        Returns:
        null for testing purpose