use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class ObservableMapTest method setUp.
@Before
public void setUp() throws Exception {
RealmTester.setDefault(new CurrentRealm(true));
map = new ObservableMapStub<>(new HashMap<>());
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableListTest method testSetBeanProperty_CorrectForNullOldAndNewValues.
@Test
public void testSetBeanProperty_CorrectForNullOldAndNewValues() {
// The java bean spec allows the old and new values in a
// PropertyChangeEvent to be null, which indicates that an unknown
// change occured.
// This test ensures that JavaBeanObservableValue fires the correct
// value diff even if the bean implementor is lazy :-P
Bean bean = new AnnoyingBean();
bean.setList(Collections.singletonList("old"));
IObservableList observable = BeansObservables.observeList(new CurrentRealm(true), bean, "list");
ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);
bean.setList(Collections.singletonList("new"));
assertEquals(1, tracker.count);
List list = new ArrayList();
list.add("old");
tracker.event.diff.applyTo(list);
assertEquals(Collections.singletonList("new"), list);
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableMapTest method testSetBeanProperty_CorrectForNullOldAndNewValues.
@Test
public void testSetBeanProperty_CorrectForNullOldAndNewValues() {
// The java bean spec allows the old and new values in a
// PropertyChangeEvent to be null, which indicates that an unknown
// change occured.
// This test ensures that JavaBeanObservableValue fires the correct
// value diff even if the bean implementor is lazy :-P
WritableSet set = new WritableSet(new CurrentRealm(true));
Bean bean = new AnnoyingBean();
bean.setValue("old");
set.add(bean);
IObservableMap map = BeansObservables.observeMap(set, Bean.class, "value");
MapChangeEventTracker tracker = MapChangeEventTracker.observe(map);
bean.setValue("new");
assertEquals(1, tracker.count);
assertEquals(Collections.EMPTY_SET, tracker.event.diff.getAddedKeys());
assertEquals(Collections.singleton(bean), tracker.event.diff.getChangedKeys());
assertEquals(Collections.EMPTY_SET, tracker.event.diff.getRemovedKeys());
assertEquals("old", tracker.event.diff.getOldValue(bean));
assertEquals("new", tracker.event.diff.getNewValue(bean));
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableMapTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.
@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
Bean bean = new Bean(Collections.EMPTY_MAP);
CurrentRealm realm = new CurrentRealm(true);
IObservableMap observable = BeansObservables.observeMap(realm, bean, "map");
MapChangeEventTracker tracker = MapChangeEventTracker.observe(observable);
realm.setCurrent(false);
bean.setMap(Collections.singletonMap("key", "value"));
assertEquals(0, tracker.count);
realm.setCurrent(true);
assertEquals(1, tracker.count);
assertDiff(tracker.event.diff, Collections.EMPTY_MAP, Collections.singletonMap("key", "value"));
}
use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.
the class JavaBeanObservableSetTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.
@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
Bean bean = new Bean(Collections.EMPTY_SET);
CurrentRealm realm = new CurrentRealm(true);
IObservableSet observable = BeansObservables.observeSet(realm, bean, "set");
SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
realm.setCurrent(false);
bean.setSet(Collections.singleton("element"));
assertEquals(0, tracker.count);
realm.setCurrent(true);
assertEquals(1, tracker.count);
assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections.singleton("element"));
}
Aggregations