3

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.

Bill P
  • 3,622
  • 10
  • 20
  • 32
CobraKai
  • 87
  • 1
  • 6

2 Answers2

3

You need to give until a callable. ie

await().until(() -> result.contains("banana"));
Tom Squires
  • 8,848
  • 12
  • 46
  • 72
1

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)

Malt
  • 28,965
  • 9
  • 65
  • 105
  • Thanks! Changed this now to this: .until(new Callable() { @Override public Boolean call() throws Exception { return (result).contains("banana"); } }); And it seems to work fine :) – CobraKai Oct 02 '19 at 13:04
  • @CobraKai Glad to hear. – Malt Oct 02 '19 at 13:04