Hi!
I've been looking in the wiki and the javadoc, but can't seem to find a solution for my problem.
I'd like to have Awaitility wait for a certain event and log message A if the event has happened before the timeout or log message B if the timeout was reached without the event happening. (Or call methods A or B in the more generic case)
The current solution looks like this:
try {
Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10000, TimeUnit.MILLISECONDS).until(() -> someEventHasHappened());
LOG.log("A");
} catch (ConditionTimeoutException cte) {
LOG.log("B");
}
But this is a bit too long and cumbersome for repeated use.
Ideally the solution would look something like this:
Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10000, TimeUnit.MILLISECONDS).until(() -> someEventHasHappened()).thenLog("A).orElseLog("B");
Of course, that is way too specific, so more realistically maybe something like this:
Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10000, TimeUnit.MILLISECONDS).until(() -> someEventHasHappened()).then(logMessageA).else(logMessageB);
Where the logMessageX variables would be Callables, of which the correct one is called upon exiting normally or timeouting.
Or is there maybe any other mechanism, pattern or hack to distinguish between exits due to the condition being fulfilled and exits due to the timeout being reached that does not involve a try-catch(ConditionTimeoutException) block and so can be written on one-two lines? For example:
Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS).await("someName").atMost(10000, TimeUnit.MILLISECONDS).until(() -> someEventHasHappened());
Awaitility.completedBeforeTimeout("someName") ? LOG.log("A") : LOG.log("B");
Thank you in advance!