I am trying to find out a way to avoid the kind of repetition below
try {
await().pollInterval(5, TimeUnit.SECONDS).pollDelay(500, TimeUnit.MILLISECONDS)
.atMost(30, TimeUnit.SECONDS).until(() -> {
// 1. methods in here
});
} catch (final Exception e) {
//TODO: can be handled internally
}
It happens in several places in my code, and I want to make it less repetitive, but I am not finding a way to do so. I thought about lambdas, but I don`t know much about it nor if it would fit in here.
Inside of it can be many different things, it is not the same for all nor they have the same inheritance.
CodePudding user response:
public static void main(String... args) {
awaitUntil(() -> {
// payload 1
return true;
});
awaitUntil(() -> {
// payload 2
return true;
});
}
public static void awaitUntil(Callable<Boolean> conditionEvaluator) {
try {
Awaitility.await()
.pollInterval(5, TimeUnit.SECONDS)
.pollDelay(500, TimeUnit.MILLISECONDS)
.atMost(30, TimeUnit.SECONDS)
.until(conditionEvaluator);
} catch(Exception e) {
//TODO: can be handled internally
}
}