Search in sources :

Example 11 with CurrentRealm

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

the class JavaBeanObservableArrayBasedSetTest 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.setArray(new Object[] { "old" });
    IObservableSet observable = BeansObservables.observeSet(new CurrentRealm(true), bean, "array");
    SetChangeEventTracker tracker = SetChangeEventTracker.observe(observable);
    bean.setArray(new Object[] { "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)

Example 12 with CurrentRealm

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

the class ObservableContractTest method testConstruction_CallsObservableCreated.

@Test
public void testConstruction_CallsObservableCreated() {
    final IObservable[] created = new IObservable[1];
    IObservable[] collected = ObservableTracker.runAndCollect(() -> created[0] = delegate.createObservable(new CurrentRealm(true)));
    assertTrue(collected.length > 0);
    boolean wasCollected = false;
    for (IObservable c : collected) {
        if (c == created[0]) {
            wasCollected = true;
            break;
        }
    }
    assertTrue(wasCollected);
}
Also used : IObservable(org.eclipse.core.databinding.observable.IObservable) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 13 with CurrentRealm

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

the class ObservableListContractTest method testGet_GetterCalled.

@Test
public void testGet_GetterCalled() throws Exception {
    list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
    assertGetterCalled(() -> list.get(0), "List.get(int)", list);
}
Also used : CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 14 with CurrentRealm

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

the class ObservableListContractTest method testListIteratorAtIndex_GetterCalled.

@Test
public void testListIteratorAtIndex_GetterCalled() throws Exception {
    // Create a new list instead of adding an item because the list might
    // not be mutable
    list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
    assertGetterCalled(() -> list.listIterator(0), "List.listIterator(int)", list);
}
Also used : CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 15 with CurrentRealm

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

the class ObservableListContractTest method testSubList_GetterCalled.

@Test
public void testSubList_GetterCalled() throws Exception {
    list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
    assertGetterCalled(() -> list.subList(0, 1), "List.subList(int, int)", list);
}
Also used : CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

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