Search in sources :

Example 11 with SetChangeEventTracker

use of org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker 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)

Example 12 with SetChangeEventTracker

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

the class JavaBeanObservableSetTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    bean = new Bean();
    propertyName = "set";
    propertyDescriptor = ((IBeanProperty) BeanProperties.set(Bean.class, propertyName)).getPropertyDescriptor();
    observableSet = BeansObservables.observeSet(DisplayRealm.getRealm(Display.getDefault()), bean, propertyName, Bean.class);
    beanObservable = (IBeanObservable) observableSet;
    listener = new SetChangeEventTracker();
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Before(org.junit.Before)

Example 13 with SetChangeEventTracker

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

the class UnmodifiableObservableSetTest method testFiresSetChangeEvents.

@Test
public void testFiresSetChangeEvents() throws Exception {
    SetChangeEventTracker mutableListener = new SetChangeEventTracker();
    SetChangeEventTracker unmodifiableListener = new SetChangeEventTracker();
    mutable.addSetChangeListener(mutableListener);
    unmodifiable.addSetChangeListener(unmodifiableListener);
    assertEquals(0, mutableListener.count);
    assertEquals(0, unmodifiableListener.count);
    String element = "3";
    mutable.add(element);
    assertEquals(1, mutableListener.count);
    assertEquals(mutable, mutableListener.event.getObservableSet());
    assertEquals(1, mutableListener.event.diff.getAdditions().size());
    Object addition = mutableListener.event.diff.getAdditions().toArray()[0];
    assertEquals(element, addition);
    assertEquals(3, mutable.size());
    assertEquals(1, unmodifiableListener.count);
    assertEquals(unmodifiable, unmodifiableListener.event.getObservableSet());
    assertEquals(1, unmodifiableListener.event.diff.getAdditions().size());
    addition = unmodifiableListener.event.diff.getAdditions().toArray()[0];
    assertEquals(element, addition);
    assertEquals(3, unmodifiable.size());
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) ObservableCollectionContractTest(org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest)

Example 14 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testAdd_SetChangeEvent.

@Test
public void testAdd_SetChangeEvent() throws Exception {
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertEquals(0, listener.count);
    String element = "1";
    set.add(element);
    assertEquals(1, listener.count);
    SetChangeEvent event = listener.event;
    assertSame(set, event.getObservableSet());
    assertEquals(Collections.singleton(element), event.diff.getAdditions());
    assertEquals(Collections.EMPTY_SET, event.diff.getRemovals());
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) SetChangeEvent(org.eclipse.core.databinding.observable.set.SetChangeEvent) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Example 15 with SetChangeEventTracker

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

the class JavaBeanObservableArrayBasedSetTest method testSetBeanProperty_FiresSetChangeEvents.

@Test
public void testSetBeanProperty_FiresSetChangeEvents() throws Exception {
    SetChangeEventTracker listener = SetChangeEventTracker.observe(set);
    assertEquals(0, listener.count);
    bean.setArray(new String[] { "element" });
    assertEquals(1, listener.count);
}
Also used : SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) Test(org.junit.Test) MutableObservableSetContractTest(org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)

Aggregations

SetChangeEventTracker (org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)21 Test (org.junit.Test)17 MutableObservableSetContractTest (org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)15 IObservableSet (org.eclipse.core.databinding.observable.set.IObservableSet)8 SetChangeEvent (org.eclipse.core.databinding.observable.set.SetChangeEvent)5 HashSet (java.util.HashSet)4 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)4 Collection (java.util.Collection)2 Set (java.util.Set)2 IObservableCollection (org.eclipse.core.databinding.observable.IObservableCollection)2 ObservableCollectionContractTest (org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest)2 TestCollection (org.eclipse.jface.databinding.conformance.util.TestCollection)2 ArrayList (java.util.ArrayList)1 IObservablesListener (org.eclipse.core.databinding.observable.IObservablesListener)1 ChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ChangeEventTracker)1 Before (org.junit.Before)1