Search in sources :

Example 26 with CurrentRealm

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

the class JavaBeanObservableArrayBasedSetTest method testSetBeanPropertyOutsideRealm_FiresEventInsideRealm.

@Test
public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() {
    Bean bean = new Bean(new Object[0]);
    CurrentRealm realm = new CurrentRealm(true);
    IObservableSet observable = BeansObservables.observeSet(realm, bean, "array");
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
    realm.setCurrent(false);
    bean.setArray(new Object[] { "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)

Example 27 with CurrentRealm

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

the class MultiValidatorTest method testObserveValidatedValue_WrongRealm.

@Test
public void testObserveValidatedValue_WrongRealm() {
    Realm otherRealm = new CurrentRealm(true);
    try {
        validator.observeValidatedValue(new WritableValue<>(otherRealm));
        fail("Expected AssertionFailedException");
    } catch (AssertionFailedException expected) {
    }
}
Also used : Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) Test(org.junit.Test)

Example 28 with CurrentRealm

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

the class WritableListTest method testCollectionConstructorsCopy_2.

@Test
public void testCollectionConstructorsCopy_2() {
    List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c"));
    WritableList<String> wlist = new WritableList<String>(new CurrentRealm(true), (Collection<String>) list, Object.class);
    wlist.remove(1);
    assertEquals(3, list.size());
    list.add("d");
    assertEquals(2, wlist.size());
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ArrayList(java.util.ArrayList) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Example 29 with CurrentRealm

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

the class WritableListTest method testRemoveRealmChecks.

@Test
public void testRemoveRealmChecks() throws Exception {
    RealmTester.setDefault(new CurrentRealm(true));
    final WritableList<String> list = new WritableList<>();
    list.add("");
    list.add("");
    RealmTester.exerciseCurrent(() -> list.remove(""));
    RealmTester.setDefault(null);
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

Example 30 with CurrentRealm

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

the class WritableListTest method testCollectionConstructorsCopy_1.

@Test
public void testCollectionConstructorsCopy_1() {
    RealmTester.setDefault(new CurrentRealm(true));
    List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c"));
    WritableList<String> wlist = new WritableList<>((Collection<String>) list, Object.class);
    wlist.remove(1);
    assertEquals(3, list.size());
    list.add("d");
    assertEquals(2, wlist.size());
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ArrayList(java.util.ArrayList) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) MutableObservableListContractTest(org.eclipse.jface.databinding.conformance.MutableObservableListContractTest)

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