Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Delaigue2016-10-13 07:54:27 +0000
committerLaurent Delaigue2016-10-13 10:37:31 +0000
commit3c7d3d74422aa061acf2db09586db94088136e61 (patch)
tree7a468249e80b8f0b9eb6cc5d5bdd53a8c3d610c3 /plugins/org.eclipse.emf.compare.tests/src/org
parent78e37cb0bbd9d806af97dfdae8f48db30a5d1cf7 (diff)
downloadorg.eclipse.emf.compare-3c7d3d74422aa061acf2db09586db94088136e61.tar.gz
org.eclipse.emf.compare-3c7d3d74422aa061acf2db09586db94088136e61.tar.xz
org.eclipse.emf.compare-3c7d3d74422aa061acf2db09586db94088136e61.zip
[501864] Refactoring of group providers & filters
Diffs that have no real conflict (direct or indirect) and only some pseudo-conflicts (but also non-conflicting refining diffs) only appear in the side group. Also add javadoc to describe the expected behaviour of the group provider 'by side' and some unit tests for predicates. Change-Id: I3d02172b1c77199ea0904459b196289b19db35d6 Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java11
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/EMFComparePredicatesTest.java182
2 files changed, 188 insertions, 5 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 38afa7a79..4a1003a90 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
@@ -13,10 +13,6 @@
*******************************************************************************/
package org.eclipse.emf.compare.tests.suite;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.textui.TestRunner;
-
import org.eclipse.emf.compare.ComparePackage;
import org.eclipse.emf.compare.tests.command.CommandStackTestSuite;
import org.eclipse.emf.compare.tests.conflict.ConflictDetectionTest;
@@ -65,6 +61,7 @@ import org.eclipse.emf.compare.tests.postprocess.PostProcessorTest;
import org.eclipse.emf.compare.tests.req.ReqComputingTest;
import org.eclipse.emf.compare.tests.scope.ComparisonScopeAdapterTest;
import org.eclipse.emf.compare.tests.scope.DefaultComparisonScopeTest;
+import org.eclipse.emf.compare.tests.utils.EMFComparePredicatesTest;
import org.eclipse.emf.compare.tests.utils.EqualityHelperTest;
import org.eclipse.emf.compare.tests.utils.MatchUtilFeatureContainsTest;
import org.eclipse.emf.ecore.EPackage;
@@ -74,6 +71,10 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Test;
+import junit.textui.TestRunner;
+
/**
* This test suite allows us to launch all tests for EMF Compare at once.
*
@@ -96,7 +97,7 @@ import org.junit.runners.Suite.SuiteClasses;
MultiLineAttributeMergeTest.class, MonitorCancelTest.class, IdentifierEObjectMatcherTest.class,
MatchUtilFeatureContainsTest.class, RefineMergeTest.class, Bug484557ConflictTest.class,
Bug485266_MoveDeleteConflict_Test.class, ResourceAttachmentChangeBug492261.class,
- ComparisonScopeAdapterTest.class, })
+ ComparisonScopeAdapterTest.class, EMFComparePredicatesTest.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/EMFComparePredicatesTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/EMFComparePredicatesTest.java
new file mode 100644
index 000000000..679ba6db1
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/EMFComparePredicatesTest.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.utils;
+
+import static com.google.common.base.Predicates.equalTo;
+import static com.google.common.base.Predicates.instanceOf;
+import static java.util.Arrays.asList;
+import static org.eclipse.emf.compare.ConflictKind.PSEUDO;
+import static org.eclipse.emf.compare.ConflictKind.REAL;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.allAtomicRefining;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.anyRefining;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasDirectOrIndirectConflict;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasNoDirectOrIndirectConflict;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.compare.AttributeChange;
+import org.eclipse.emf.compare.CompareFactory;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Conflict;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.junit.Test;
+
+public class EMFComparePredicatesTest {
+
+ private CompareFactory factory = CompareFactory.eINSTANCE;
+
+ @Test
+ public void testAnyRefiningWithoutRecursion() {
+ Comparison comp = factory.createComparison();
+ Match rootMatch = factory.createMatch();
+ comp.getMatches().add(rootMatch);
+
+ AttributeChange ac = factory.createAttributeChange();
+ ReferenceChange rc1 = factory.createReferenceChange();
+ ReferenceChange rc2 = factory.createReferenceChange();
+ ReferenceChange rc3 = factory.createReferenceChange();
+ EList<Diff> diffs = rootMatch.getDifferences();
+ diffs.add(ac);
+ diffs.add(rc1);
+ diffs.add(rc2);
+ diffs.add(rc3);
+ ac.getRefinedBy().addAll(asList(rc1, rc2, rc3));
+
+ assertFalse(anyRefining(instanceOf(AttributeChange.class)).apply(ac));
+ assertTrue(anyRefining(instanceOf(ReferenceChange.class)).apply(ac));
+ assertTrue(anyRefining(equalTo((Diff)rc3)).apply(ac));
+ }
+
+ @Test
+ public void testAnyRefiningWithRecursion() {
+ Comparison comp = factory.createComparison();
+ Match rootMatch = factory.createMatch();
+ comp.getMatches().add(rootMatch);
+
+ AttributeChange ac = factory.createAttributeChange();
+ AttributeChange ac1 = factory.createAttributeChange();
+ ReferenceChange rc11 = factory.createReferenceChange();
+ ReferenceChange rc12 = factory.createReferenceChange();
+ ReferenceChange rc2 = factory.createReferenceChange();
+ ReferenceChange rc3 = factory.createReferenceChange();
+ EList<Diff> diffs = rootMatch.getDifferences();
+ diffs.add(ac);
+ diffs.add(ac1);
+ diffs.add(rc11);
+ diffs.add(rc12);
+ diffs.add(rc2);
+ diffs.add(rc3);
+ ac.getRefinedBy().addAll(asList(ac1, rc2, rc3));
+ ac1.getRefinedBy().addAll(asList(rc11, rc12));
+
+ assertTrue(anyRefining(instanceOf(AttributeChange.class)).apply(ac));
+ assertTrue(anyRefining(instanceOf(ReferenceChange.class)).apply(ac));
+ assertTrue(anyRefining(equalTo((Diff)rc12)).apply(ac));
+ assertFalse(anyRefining(equalTo((Diff)ac)).apply(ac));
+ }
+
+ @Test
+ public void testAllAtomicRefiningWithoutRecursion() {
+ Comparison comp = factory.createComparison();
+ Match rootMatch = factory.createMatch();
+ comp.getMatches().add(rootMatch);
+
+ AttributeChange ac = factory.createAttributeChange();
+ ReferenceChange rc1 = factory.createReferenceChange();
+ ReferenceChange rc2 = factory.createReferenceChange();
+ ReferenceChange rc3 = factory.createReferenceChange();
+ EList<Diff> diffs = rootMatch.getDifferences();
+ diffs.add(ac);
+ diffs.add(rc1);
+ diffs.add(rc2);
+ diffs.add(rc3);
+ ac.getRefinedBy().addAll(asList(rc1, rc2, rc3));
+
+ assertFalse(allAtomicRefining(instanceOf(AttributeChange.class)).apply(ac));
+ assertTrue(allAtomicRefining(instanceOf(ReferenceChange.class)).apply(ac));
+ assertFalse(allAtomicRefining(equalTo((Diff)rc3)).apply(ac));
+ }
+
+ @Test
+ public void testAllAtomicRefiningWithRecursion() {
+ Comparison comp = factory.createComparison();
+ Match rootMatch = factory.createMatch();
+ comp.getMatches().add(rootMatch);
+
+ AttributeChange ac = factory.createAttributeChange();
+ AttributeChange ac1 = factory.createAttributeChange();
+ ReferenceChange rc11 = factory.createReferenceChange();
+ ReferenceChange rc12 = factory.createReferenceChange();
+ ReferenceChange rc2 = factory.createReferenceChange();
+ ReferenceChange rc3 = factory.createReferenceChange();
+ EList<Diff> diffs = rootMatch.getDifferences();
+ diffs.add(ac);
+ diffs.add(ac1);
+ diffs.add(rc11);
+ diffs.add(rc12);
+ diffs.add(rc2);
+ diffs.add(rc3);
+ ac.getRefinedBy().addAll(asList(ac1, rc2, rc3));
+ ac1.getRefinedBy().addAll(asList(rc11, rc12));
+
+ assertFalse(allAtomicRefining(instanceOf(AttributeChange.class)).apply(ac));
+ assertTrue(allAtomicRefining(instanceOf(ReferenceChange.class)).apply(ac));
+ assertFalse(allAtomicRefining(equalTo((Diff)rc12)).apply(ac));
+ }
+
+ @Test
+ public void testHasDirectOrIndirectConflictForDirectConflict() {
+ Comparison comp = factory.createComparison();
+ Match rootMatch = factory.createMatch();
+ comp.getMatches().add(rootMatch);
+ AttributeChange acl = factory.createAttributeChange();
+ AttributeChange acr = factory.createAttributeChange();
+ rootMatch.getDifferences().addAll(asList(acl, acr));
+ Conflict conflict = factory.createConflict();
+ conflict.setKind(REAL);
+ conflict.getDifferences().addAll(asList(acl, acr));
+ comp.getConflicts().add(conflict);
+
+ assertTrue(hasDirectOrIndirectConflict(REAL).apply(acl));
+ assertTrue(hasDirectOrIndirectConflict(REAL).apply(acr));
+ assertFalse(hasDirectOrIndirectConflict(PSEUDO).apply(acl));
+ assertFalse(hasDirectOrIndirectConflict(PSEUDO).apply(acr));
+
+ assertFalse(hasNoDirectOrIndirectConflict(REAL).apply(acl));
+ assertFalse(hasNoDirectOrIndirectConflict(REAL).apply(acr));
+ assertTrue(hasNoDirectOrIndirectConflict(PSEUDO).apply(acl));
+ assertTrue(hasNoDirectOrIndirectConflict(PSEUDO).apply(acr));
+ }
+
+ @Test
+ public void testHasDirectOrIndirectConflictForIndirectConflict() {
+ Comparison comp = factory.createComparison();
+ Match rootMatch = factory.createMatch();
+ comp.getMatches().add(rootMatch);
+ ReferenceChange rc = factory.createReferenceChange();
+ AttributeChange acl = factory.createAttributeChange();
+ AttributeChange acr = factory.createAttributeChange();
+ rootMatch.getDifferences().addAll(asList(rc, acl, acr));
+ rc.getRefinedBy().addAll(asList(acl));
+ Conflict conflict = factory.createConflict();
+ conflict.setKind(REAL);
+ conflict.getDifferences().addAll(asList(acl, acr));
+ comp.getConflicts().add(conflict);
+
+ assertTrue(hasDirectOrIndirectConflict(REAL).apply(rc));
+ assertFalse(hasDirectOrIndirectConflict(PSEUDO).apply(rc));
+ assertFalse(hasNoDirectOrIndirectConflict(REAL).apply(rc));
+ assertTrue(hasNoDirectOrIndirectConflict(PSEUDO).apply(rc));
+ }
+}

Back to the top