I'm using Awaitility tool and I need to return a collection from await to be able to work with it later.
I have a collection returned from a GET call:
Collection collection = usersService.getAllUsers();
The following code works (GET call is executed up to 5 times in order to meet the conditions):
waitForEvent(() -> usersService.getAllUsers()).size());
Where:
private void waitForEvent(Callable<Integer> collectionSize) {
await().atMost(5, TimeUnit.SECONDS)
.pollDelay(1, TimeUnit.SECONDS).until(collectionSize, greaterThan(5));
}
But I need to pass a Collection (not its size) to be able to reuse it. Why this code is not working (GET call is executed just once and it waits for 5 sec)?
waitForEvent2(usersService.getAllUsers());
Where
private Collection waitForEvent2(Collection collection) {
await().atMost(5, TimeUnit.SECONDS)
.pollDelay(1, TimeUnit.SECONDS).until(collectionSize(collection), greaterThan(5));
return collection;
}
private Callable<Integer> collectionSize(Collection collection) {
return new Callable<Integer>() {
public Integer call() throws Exception {
return collection.size(); // The condition supplier part
}
};
}
What do I need to do so that GET request was polled several times with collection passed as a parameter?