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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations