Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java7
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java95
2 files changed, 100 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index 20767fe68..5ea30df1d 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 Obeo.
+ * Copyright (c) 2012, 2015 Obeo 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
@@ -9,6 +9,7 @@
* Obeo - initial API and implementation
* Philip Langer - Adds additional test classes
* Stefan Dirix - Adds additional test classes
+ * Michael Borkowski - Adds additional test classes
*******************************************************************************/
package org.eclipse.emf.compare.tests.suite;
@@ -60,6 +61,7 @@ import org.eclipse.emf.compare.tests.rcp.AllRCPTests;
import org.eclipse.emf.compare.tests.req.ReqComputingTest;
import org.eclipse.emf.compare.tests.scope.DefaultComparisonScopeTest;
import org.eclipse.emf.compare.tests.utils.EqualityHelperTest;
+import org.eclipse.emf.compare.tests.utils.MatchUtilFeatureContainsTest;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.junit.BeforeClass;
@@ -86,7 +88,8 @@ import org.junit.runners.Suite.SuiteClasses;
FeatureMapsPseudoConflictsMergeTest.class, TwoWayBatchMergingTest.class, EqualityHelperTest.class,
FeatureFilterTest.class, ThreeWayBatchMergingTest.class,
MultiLineAttributeConflictDetectionTest.class, ThreeWayTextDiffTest.class,
- MultiLineAttributeMergeTest.class, MonitorCancelTest.class, IdentifierEObjectMatcherTest.class })
+ MultiLineAttributeMergeTest.class, MonitorCancelTest.class, IdentifierEObjectMatcherTest.class,
+ MatchUtilFeatureContainsTest.class })
public class AllTests {
/**
* Standalone launcher for all of compare's tests.
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java
new file mode 100644
index 000000000..f46559d4d
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EclipseSource Muenchen GmbH.
+ * 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:
+ * Michael Borkowski - initial tests
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.compare.utils.MatchUtil;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings({"boxing", "nls" })
+public class MatchUtilFeatureContainsTest {
+
+ List<EObject> featureList;
+
+ InternalEObject value;
+
+ EObject container;
+
+ EClass eClass;
+
+ EStructuralFeature feature;
+
+ @Before
+ public void setUp() {
+ EPackage ePackage = mock(EPackage.class);
+
+ container = mock(EObject.class);
+ feature = mock(EStructuralFeature.class);
+
+ eClass = mock(EClass.class);
+ when(eClass.getEPackage()).thenReturn(ePackage);
+
+ when(container.eClass()).thenReturn(eClass);
+ when(feature.getEContainingClass()).thenReturn(eClass);
+
+ featureList = new LinkedList<EObject>();
+ when(container.eGet(feature, false)).thenReturn(featureList);
+
+ value = mockInternalObject();
+ featureList.add(value);
+ }
+
+ @Test
+ public void test_SameObject() {
+ assertTrue(MatchUtil.featureContains(container, feature, value));
+ }
+
+ @Test
+ public void test_Proxy() {
+ URI uri = URI.createFileURI("/my/path");
+
+ InternalEObject proxyValue = mockInternalObject();
+ when(proxyValue.eIsProxy()).thenReturn(true);
+ when(proxyValue.eProxyURI()).thenReturn(uri);
+
+ when(value.eIsProxy()).thenReturn(true);
+ when(value.eProxyURI()).thenReturn(uri);
+
+ assertTrue(MatchUtil.featureContains(container, feature, proxyValue));
+ }
+
+ @Test
+ public void test_DifferentObject() {
+ InternalEObject otherValue = mockInternalObject();
+
+ assertFalse(MatchUtil.featureContains(container, feature, otherValue));
+ }
+
+ private InternalEObject mockInternalObject() {
+ InternalEObject internalObject = mock(InternalEObject.class);
+ when(internalObject.eClass()).thenReturn(eClass);
+ return internalObject;
+ }
+}

Back to the top