Bug 184817 [DataBinding] WritableMap.put(...) fires an incorrect event
The event for WritableMap.put(...) when the key already exists reverses the new and old values in the change event. The following test will fail on the old value as it will be the new value. public void testPutWithExistingKeyMapChangeEvent() throws Exception { WritableMap map = new WritableMap(); String key = "key"; String value = "value"; map.put(key, value); MapChangeEventTracker listener = new MapChangeEventTracker(); map.addMapChangeListener(listener); assertEquals(0, listener.count); String newValue = "new value"; map.put(key, newValue); assertEquals(1, listener.count); MapChangeEvent event = listener.event; Set changedKeys = event.diff.getChangedKeys(); assertEquals(1, changedKeys.size()); assertTrue(changedKeys.contains(key)); assertEquals(value, event.diff.getOldValue(key)); //<<<FAILS assertEquals(newValue, event.diff.getNewValue(key)); }
tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/EventTrackers.java
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/
package org.eclipse.jface.tests.databinding;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
/**
 * Implementations of change listeners that keep track of the number of times an
 * event fires.
 * 
 * @since 1.1
 */
public class EventTrackers {