Bug 486804 - Use equals() to check equality of EMap Entry instances
authorBrian de Alwis <bsd@mt.ca>
Fri, 29 Jan 2016 19:03:28 +0000 (14:03 -0500)
committerDani Megert <Daniel_Megert@ch.ibm.com>
Wed, 3 Feb 2016 09:51:30 +0000 (04:51 -0500)
EMF EMap#entrySet() may return wrappers instances, and must be
tested with equals() and not with ==.

Change-Id: I26a6bd30b086613a43967687940ce7632feabd55

bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/XMLModelReconciler.java
tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/reconciler/ModelReconcilerContributionTest.java
tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/reconciler/xml/XMLModelReconcilerContributionTest.java

index bcf2888..f451dbf 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 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
@@ -927,7 +927,7 @@ public class XMLModelReconciler extends ModelReconciler {
        private String getEntryElementName(EObject object, Entry<?, ?> entry) {
                if (object instanceof MContext) {
                        for (Entry<String, String> property : ((MContext) object).getProperties().entrySet()) {
-                               if (property == entry) {
+                               if (property.equals(entry)) {
                                        return CONTEXT_PROPERTIES_ATTNAME;
                                }
                        }
@@ -936,7 +936,7 @@ public class XMLModelReconciler extends ModelReconciler {
                if (object instanceof MContribution) {
                        for (Entry<String, String> state : ((MContribution) object).getPersistedState()
                                        .entrySet()) {
-                               if (state == entry) {
+                               if (state.equals(entry)) {
                                        return APPLICATIONELEMENT_PERSISTEDSTATE_ATTNAME;
                                }
                        }
index c6399f6..3e4b00c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 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
@@ -12,6 +12,7 @@
 package org.eclipse.e4.ui.tests.reconciler;
 
 import java.util.Collection;
+import java.util.Objects;
 import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
@@ -41,6 +42,8 @@ public abstract class ModelReconcilerContributionTest extends
                part.getPersistedState().put("testing", userChange);
 
                Object state = reconciler.serialize();
+               assertEquals(!Objects.equals(applicationState, userChange),
+                               serializedStateHasChanges(state));
 
                application = createApplication();
                window = application.getChildren().get(0);
@@ -48,6 +51,7 @@ public abstract class ModelReconcilerContributionTest extends
                part.getPersistedState().put("testing", newApplicationState);
 
                Collection<ModelDelta> deltas = constructDeltas(application, state);
+               assertEquals(Objects.equals(applicationState, userChange) ? 0 : 1, deltas.size());
 
                assertEquals(newApplicationState, part.getPersistedState().get(
                                "testing"));
@@ -73,6 +77,14 @@ public abstract class ModelReconcilerContributionTest extends
                }
        }
 
+       /**
+        * @param state
+        * @return true if the state object, returned from
+        *         {@link ModelReconciler#serialize()} when recording changes,
+        *         actually has changes recorded.
+        */
+       protected abstract boolean serializedStateHasChanges(Object state);
+
        public void testContribution_PersistedState_NullNullNull() {
                testContribution_PersistedState(null, null, null);
        }
index c086670..83410a5 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 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
@@ -23,4 +23,11 @@ public class XMLModelReconcilerContributionTest extends
                return new ModelReconcilingService();
        }
 
+       protected boolean serializedStateHasChanges(Object state) {
+               assertTrue(state instanceof org.w3c.dom.Document);
+               org.w3c.dom.Document doc = (org.w3c.dom.Document) state;
+               assertTrue(doc.hasChildNodes() && doc.getChildNodes().getLength() == 1
+                               && "changes".equals(doc.getFirstChild().getNodeName()));
+               return doc.getFirstChild().hasChildNodes();
+       }
 }