Search in sources :

Example 6 with CurrentRealm

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<>());
}
Also used : HashMap(java.util.HashMap) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Before(org.junit.Before)

Example 7 with CurrentRealm

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);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Example 8 with CurrentRealm

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));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 9 with CurrentRealm

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"));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 10 with CurrentRealm

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"));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Aggregations

CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)39 Test (org.junit.Test)35 MutableObservableListContractTest (org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)10 ObservableListContractTest (org.eclipse.jface.databinding.conformance.ObservableListContractTest)10 ArrayList (java.util.ArrayList)7 Realm (org.eclipse.core.databinding.observable.Realm)6 WritableList (org.eclipse.core.databinding.observable.list.WritableList)6 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)5 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)4 IObservableSet (org.eclipse.core.databinding.observable.set.IObservableSet)4 MutableObservableSetContractTest (org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)4 ListChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker)4 SetChangeEventTracker (org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)4 Before (org.junit.Before)4 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)3 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)3 MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)3 List (java.util.List)2 IObservable (org.eclipse.core.databinding.observable.IObservable)2 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)2