Search in sources :

Example 16 with CurrentRealm

use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.

the class ValidatedObservableValueTest method testConstructor_RequireObservablesOnSameRealm.

@Test
public void testConstructor_RequireObservablesOnSameRealm() {
    CurrentRealm realm1 = new CurrentRealm(true);
    CurrentRealm realm2 = new CurrentRealm(true);
    target = new ObservableValueStub(realm1);
    validationStatus = new WritableValue(realm2);
    try {
        new ValidatedObservableValue(target, validationStatus);
        fail("Expected exception--target and validation status should have the same realm");
    } catch (RuntimeException expected) {
    }
}
Also used : CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) ValidatedObservableValue(org.eclipse.core.internal.databinding.validation.ValidatedObservableValue) MutableObservableValueContractTest(org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest) Test(org.junit.Test)

Example 17 with CurrentRealm

use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableListTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.

@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
    Bean bean = new Bean(Collections.EMPTY_LIST);
    CurrentRealm realm = new CurrentRealm(true);
    IObservableList observable = BeansObservables.observeList(realm, bean, "list");
    ListChangeEventTracker tracker = ListChangeEventTracker.observe(observable);
    realm.setCurrent(false);
    bean.setList(Collections.singletonList("element"));
    assertEquals(0, tracker.count);
    realm.setCurrent(true);
    assertEquals(1, tracker.count);
    assertDiff(tracker.event.diff, Collections.EMPTY_LIST, Collections.singletonList("element"));
}
Also used : 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 18 with CurrentRealm

use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableMapTest method testConstructor_SkipRegisterListeners.

@Test
public void testConstructor_SkipRegisterListeners() throws Exception {
    Realm realm = new CurrentRealm(true);
    WritableSet set = new WritableSet(realm);
    Bean bean = new Bean();
    set.add(bean);
    IObservableMap observable = PojoObservables.observeMap(set, Bean.class, "value");
    assertFalse(bean.hasListeners("value"));
    ChangeEventTracker.observe(observable);
    assertFalse(bean.hasListeners("value"));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) Realm(org.eclipse.core.databinding.observable.Realm) ThreadRealm(org.eclipse.core.tests.databinding.observable.ThreadRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 19 with CurrentRealm

use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableMapTest method testConstructor_RegistersListeners.

@Test
public void testConstructor_RegistersListeners() throws Exception {
    Realm realm = new CurrentRealm(true);
    WritableSet set = new WritableSet(realm);
    Bean bean = new Bean();
    set.add(bean);
    IObservableMap observable = BeansObservables.observeMap(set, Bean.class, "value");
    assertFalse(bean.hasListeners("value"));
    ChangeEventTracker.observe(observable);
    assertTrue(bean.hasListeners("value"));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) Realm(org.eclipse.core.databinding.observable.Realm) ThreadRealm(org.eclipse.core.tests.databinding.observable.ThreadRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 20 with CurrentRealm

use of org.eclipse.jface.databinding.conformance.util.CurrentRealm in project eclipse.platform.ui by eclipse-platform.

the class JavaBeanObservableSetTest 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.setSet(Collections.singleton("old"));
    IObservableSet observable = BeansObservables.observeSet(new CurrentRealm(true), bean, "set");
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
    bean.setSet(Collections.singleton("new"));
    assertEquals(1, tracker.count);
    assertEquals(Collections.singleton("old"), tracker.event.diff.getRemovals());
    assertEquals(Collections.singleton("new"), tracker.event.diff.getAdditions());
}
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