EntityAsserts { public static void assertAttributeChangesEventually(final Entity entity, final AttributeSensor<?> attribute) { final Object origValue = entity.getAttribute(attribute); final AtomicBoolean changed = new AtomicBoolean(); SubscriptionHandle handle = entity.subscriptions().subscribe(entity, attribute, new SensorEventListener<Object>() { @Override public void onEvent(SensorEvent<Object> event) { if (!Objects.equal(origValue, event.getValue())) { changed.set(true); } }}); try { Asserts.succeedsEventually(new Runnable() { @Override public void run() { Asserts.assertTrue(changed.get(), entity + " -> " + attribute + " not changed from "+origValue); }}); } finally { entity.subscriptions().unsubscribe(entity, handle); } }  static void assertAttributeEquals(Entity entity, AttributeSensor<T> attribute, T expected); static void assertConfigEquals(Entity entity, ConfigKey<T> configKey, T expected); static void assertAttributeEqualsEventually(final Entity entity, final AttributeSensor<T> attribute, final T expected); static void assertAttributeEqualsEventually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final T expected); static T assertAttributeEventuallyNonNull(final Entity entity, final AttributeSensor<T> attribute); static T assertAttributeEventuallyNonNull(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute); static T assertAttributeEventually(final Entity entity, final AttributeSensor<T> attribute, Predicate<? super T> predicate); static T assertAttributeEventually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final Predicate<? super T> predicate); static T assertAttribute(final Entity entity, final AttributeSensor<T> attribute, final Predicate<? super T> predicate); static void assertPredicateEventuallyTrue(final T entity, final Predicate<? super T> predicate); static void assertPredicateEventuallyTrue(Map<?,?> flags, final T entity, final Predicate<? super T> predicate); static void assertAttributeEqualsContinually(final Entity entity, final AttributeSensor<T> attribute, final T expected); static void assertAttributeEqualsContinually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final T expected); static void assertGroupSizeEqualsEventually(final Group group, int expected); static void assertGroupSizeEqualsEventually(Map<?,?> flags, final Group group, final int expected); static void assertAttributeChangesEventually(final Entity entity, final AttributeSensor<?> attribute); @Beta @SafeVarargs static void assertAttributeContinuallyNotEqualTo(final Entity entity, final AttributeSensor<T> attribute, T... disallowed); @Beta @SafeVarargs static void assertAttributeContinuallyNotEqualTo(final Map<?, ?> flags, final Entity entity, final AttributeSensor<T> attribute, T... disallowed); static void assertEntityHealthy(Entity entity); static void assertEntityHealthyEventually(Entity entity); @Beta static void assertEntityFailed(Entity entity);  }
@Test public void shouldAssertAttributeChangesEventually () throws Exception{ entity.sensors().set(TestEntity.NAME, "before"); final Task<?> assertValue = entity.getExecutionContext().submit("check attr change", () -> EntityAsserts.assertAttributeChangesEventually(entity, TestEntity.NAME)); Repeater.create() .repeat(() -> entity.sensors().set(TestEntity.NAME, "after" + System.currentTimeMillis())) .until(() -> assertValue.isDone()) .every(Duration.millis(10)) .run(); assertValue.get(); }