@Test public void testIsSatisfied() throws Exception { Predicate<Integer> isEven = new Predicate<Integer>() { @Override public boolean apply(Integer input) { return (input % 2 == 0); } }; Assert.assertFalse(Functionals.isSatisfied(11, isEven).call()); Assert.assertTrue(Functionals.isSatisfied(22, isEven).call()); }
/** Waits until the passed entity satisfies the supplied predicate. */ public static void waitFor(Entity entity, Predicate<Entity> condition, Duration timeout) { try { String description = "Waiting for " + condition + " on " + entity; Tasks.setBlockingDetails(description); Repeater repeater = Repeater.create(description) .until(isSatisfied(entity, condition)) .limitTimeTo(timeout) .backoffTo(Duration.ONE_SECOND) .rethrowException(); if (!repeater.run()) { throw new IllegalStateException("Timeout waiting for " + condition + " on " + entity); } } finally { Tasks.resetBlockingDetails(); } log.debug("Detected {} for {}", condition, entity); }