AbstractProperty extends AbstractObservableValue<T> implements SettableValue<T> { @NotNull public static List<AbstractProperty<?>> getAll(Object object) { ArrayList<AbstractProperty<?>> properties = new ArrayList<>(); for (Field field : object.getClass().getDeclaredFields()) { if (AbstractProperty.class.isAssignableFrom(field.getType())) { try { boolean isFieldPrivate = !field.isAccessible(); field.setAccessible(true); properties.add((AbstractProperty<?>)field.get(object)); if (isFieldPrivate) { field.setAccessible(false); } } catch (IllegalAccessException ignored) { } } } return properties; }  @NotNull static List<AbstractProperty<?>> getAll(Object object); final void addConstraint(@NotNull Constraint<T> constraint); @Override final void set(@NotNull T value); final void set(@NotNull ObservableValue<T> value); @Override String toString();  }
@Test public void testGetAll() { TestInvokeStrategy testStrategy = new TestInvokeStrategy(); ListenerManager listeners = new ListenerManager(testStrategy); ObjectWithObservableProperties dummy = new ObjectWithObservableProperties(); CountingRunnable counter = new CountingRunnable(); List<AbstractProperty<?>> dummyProperties = AbstractProperty.getAll(dummy); assert !dummyProperties.isEmpty(); listeners.listenAll(dummyProperties).with(counter); assertThat(counter.myRunCount).isEqualTo(0); dummy.bool().set(true); testStrategy.updateOneStep(); assertThat(counter.myRunCount).isEqualTo(1); dummy.integer().set(1); testStrategy.updateOneStep(); assertThat(counter.myRunCount).isEqualTo(2); dummy._double().set(1.0); testStrategy.updateOneStep(); assertThat(counter.myRunCount).isEqualTo(3); dummy.string.set("test"); testStrategy.updateOneStep(); assertThat(counter.myRunCount).isEqualTo(4); }
@Test public void testGetAllWithNoObservableProperties() { ObjectWithNoObservableProperties object = new ObjectWithNoObservableProperties(false, 42, 42.0, "test"); List<AbstractProperty<?>> properties = AbstractProperty.getAll(object); assert properties.isEmpty(); }