Search in sources :

Example 6 with SetChangeEventTracker

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

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

the class MutableObservableSetContractTest method assertRemoveDiffEntry.

/**
 * Asserts the set diff entry for a remove operation.
 *
 * @param runnable
 * @param methodName
 * @param set
 * @param element
 */
private void assertRemoveDiffEntry(Runnable runnable, String methodName, IObservableSet set, Object element) {
    SetChangeEventTracker listener = new SetChangeEventTracker();
    set.addSetChangeListener(listener);
    runnable.run();
    Set entries = listener.event.diff.getRemovals();
    assertEquals(formatFail(methodName + " should result in one diff entry."), 1, entries.size());
    assertTrue(formatFail(methodName + " should result in a diff entry that is a removal."), entries.contains(element));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) Set(java.util.Set) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)

Example 8 with SetChangeEventTracker

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

the class MutableObservableSetContractTest method assertAddDiffEntry.

/**
 * Asserts the set diff entry for an add operation.
 *
 * @param runnable
 * @param methodName
 * @param set
 * @param element
 */
private void assertAddDiffEntry(Runnable runnable, String methodName, IObservableSet set, Object element) {
    SetChangeEventTracker listener = new SetChangeEventTracker();
    set.addSetChangeListener(listener);
    runnable.run();
    Set entries = listener.event.diff.getAdditions();
    assertEquals(formatFail(methodName + " should result in one diff entry."), 1, entries.size());
    assertTrue(formatFail(methodName + " should result in a diff entry that is an addition."), entries.contains(element));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) Set(java.util.Set) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)

Example 9 with SetChangeEventTracker

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

the class MutableObservableSetContractTest method assertSetChangeEventFired.

/**
 * Asserts standard behaviors of firing set change events.
 * <ul>
 * <li>Event fires once.</li>
 * <li>Source of the event is the provided <code>set</code>.
 * <li>The set change event is fired after the change event.</li>
 * </ul>
 *
 * @param runnable
 * @param methodName
 * @param set
 */
private void assertSetChangeEventFired(Runnable runnable, String methodName, IObservableSet set) {
    List<IObservablesListener> queue = new ArrayList<>();
    SetChangeEventTracker setListener = new SetChangeEventTracker(queue);
    ChangeEventTracker changeListener = new ChangeEventTracker(queue);
    set.addSetChangeListener(setListener);
    set.addChangeListener(changeListener);
    runnable.run();
    assertEquals(formatFail(methodName + " should fire one SetChangeEvent."), 1, setListener.count);
    assertEquals(formatFail(methodName + "'s change event observable should be the created Set."), set, setListener.event.getObservable());
    assertEquals(formatFail("Two notifications should have been received."), 2, queue.size());
    assertEquals(formatFail("ChangeEvent of " + methodName + " should have fired before the SetChangeEvent."), changeListener, queue.get(0));
    assertEquals(formatFail("SetChangeEvent of " + methodName + " should have fired after the ChangeEvent."), setListener, queue.get(1));
}
Also used : IObservablesListener(org.eclipse.core.databinding.observable.IObservablesListener) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker) ChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ChangeEventTracker) ArrayList(java.util.ArrayList) SetChangeEventTracker(org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker)

Example 10 with SetChangeEventTracker

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

the class JavaBeanObservableSetTest method testRegistersListenerAfterFirstListenerIsAdded.

@Test
public void testRegistersListenerAfterFirstListenerIsAdded() throws Exception {
    assertFalse(bean.changeSupport.hasListeners(propertyName));
    observableSet.addSetChangeListener(new SetChangeEventTracker());
    assertTrue(bean.changeSupport.hasListeners(propertyName));
}
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