javaawaitility

Awaitatility, polling until condition is met


i'm trying to use awaitatility for some testing purposes.

This piece of code im trying to use is giving me problems:

    await()
            .atLeast(Duration.ONE_HUNDRED_MILLISECONDS)
            .atMost(Duration.FIVE_SECONDS)
            .with()
            .pollInterval(Duration.ONE_HUNDRED_MILLISECONDS)
            .until(result.contains("banana"));

Result is a string variable in which i save some remote system output earlier in the code. But when i try to use it like this, i get the following error :

"until (java.util.concurrent.Callable) in ConditionFactory cannot be applied to (boolean)"

What is the proper way to use the library? I want too see if certain data/text string has managed to get retrieved from my remote system before i do a bunch of asserts on the data fetched.


Solution

  • until needs to take a function that returns a boolean (i.e. a Callable<Boolean>), not just a boolean.

    result.contains("banana") is a method call that returns a boolean. That means that .until(result.contains("banana")) is evaluated to .until(false) or .until(true)