Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2012-08-03 06:29:54 -0400
committerMikaël Barbero2012-08-03 06:29:54 -0400
commit1792c3415d947badd7c29c8c2021495c06afdadc (patch)
tree02a50f15206ae852ca5813c9c3d7ef493345a8b0 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff
parent6fd196ea0a743ebf652d72ccac6d980c8c0e1b07 (diff)
downloadorg.eclipse.emf.compare-1792c3415d947badd7c29c8c2021495c06afdadc.tar.gz
org.eclipse.emf.compare-1792c3415d947badd7c29c8c2021495c06afdadc.tar.xz
org.eclipse.emf.compare-1792c3415d947badd7c29c8c2021495c06afdadc.zip
add a EMFCompareConfiguration class to configure the match/diff/merge
process. Currently, it holds a Monitor and an EqualityHelper but can be augmented without breaking APIs (it's a class). The configuration can be retrieved from a Comparison object through an EOperation and is technically stored as an Adapter on the Comparison object.
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java32
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java159
2 files changed, 83 insertions, 108 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java
index 36d1c9587..9f01ef6ab 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffEngineTest.java
@@ -19,9 +19,9 @@ import java.util.List;
import org.eclipse.emf.compare.CompareFactory;
import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.EMFCompareConfiguration;
import org.eclipse.emf.compare.diff.DefaultDiffEngine;
import org.eclipse.emf.compare.utils.DiffUtil;
-import org.eclipse.emf.compare.utils.EqualityHelper;
import org.junit.Test;
/**
@@ -36,9 +36,8 @@ public class DiffEngineTest {
final List<Character> left = Lists.charactersOf("abcde");
final List<Character> right = Lists.charactersOf("czdab");
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
/*
* This is documented in {@link DefaultDiffEngine#longestCommonSubsequence(Comparison, List, List)}.
@@ -52,9 +51,8 @@ public class DiffEngineTest {
final List<Character> left = Lists.charactersOf("abcde");
final List<Character> right = Lists.charactersOf("ycdeb");
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
/*
* This is documented in {@link DefaultDiffEngine#longestCommonSubsequence(Comparison, List, List)}.
@@ -68,9 +66,8 @@ public class DiffEngineTest {
final List<Integer> left = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7);
final List<Integer> right = Lists.newArrayList(8, 9, 2, 3, 4, 1, 0);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
// These are the origin and left sides of the "complex" conflict test case.
assertEqualContents(Lists.newArrayList(2, 3, 4), lcs);
@@ -81,9 +78,8 @@ public class DiffEngineTest {
final List<Integer> left = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7);
final List<Integer> right = Lists.newArrayList(6, 2, 9, 3, 0, 4, 1, 7);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
// These are the origin and right sides of the "complex" conflict test case.
assertEqualContents(Lists.newArrayList(2, 3, 4, 7), lcs);
@@ -106,4 +102,14 @@ public class DiffEngineTest {
assertEquals(list1.get(i), list2.get(i));
}
}
+
+ /**
+ * Creates and return a new empty {@link Comparison} object with a defaut {@link EMFCompareConfiguration}.
+ *
+ * @return the created {@link Comparison}.
+ */
+ private static Comparison createEmptyComparison() {
+ final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ return emptyComparison;
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
index 9c75ad4ff..a18267019 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
@@ -19,8 +19,8 @@ import java.util.List;
import org.eclipse.emf.compare.CompareFactory;
import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.EMFCompareConfiguration;
import org.eclipse.emf.compare.utils.DiffUtil;
-import org.eclipse.emf.compare.utils.EqualityHelper;
import org.junit.Test;
/**
@@ -35,9 +35,8 @@ public class DiffUtilTest {
final List<Character> left = Lists.charactersOf("abcde");
final List<Character> right = Lists.charactersOf("czdab");
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
/*
* This is documented in {@link DefaultDiffEngine#longestCommonSubsequence(Comparison, List, List)}.
@@ -51,9 +50,8 @@ public class DiffUtilTest {
final List<Character> left = Lists.charactersOf("abcde");
final List<Character> right = Lists.charactersOf("ycdeb");
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Character> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
/*
* This is documented in {@link DefaultDiffEngine#longestCommonSubsequence(Comparison, List, List)}.
@@ -67,9 +65,8 @@ public class DiffUtilTest {
final List<Integer> left = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7);
final List<Integer> right = Lists.newArrayList(8, 9, 2, 3, 4, 1, 0);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
// These are the origin and left sides of the "complex" conflict test case.
assertEqualContents(Lists.newArrayList(2, 3, 4), lcs);
@@ -80,9 +77,8 @@ public class DiffUtilTest {
final List<Integer> left = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7);
final List<Integer> right = Lists.newArrayList(6, 2, 9, 3, 0, 4, 1, 7);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
- final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, new EqualityHelper(),
- left, right);
+ final Comparison emptyComparison = createEmptyComparison();
+ final List<Integer> lcs = DiffUtil.longestCommonSubsequence(emptyComparison, left, right);
// These are the origin and right sides of the "complex" conflict test case.
assertEqualContents(Lists.newArrayList(2, 3, 4, 7), lcs);
@@ -109,33 +105,29 @@ public class DiffUtilTest {
// add "6" in right = {8, 9, 2, 3, 4, 1, 0, 6}
final List<Integer> left = Lists.newArrayList(8, 9, 2, 3, 4, 1, 0, 6);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
// Merge the move of "1" (assume 1 already removed from right)
List<Integer> right = Lists.newArrayList(6, 2, 9, 3, 0, 4, 7);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(1));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(1));
// Inserted just before "0"
assertSame(Integer.valueOf(4), Integer.valueOf(insertionIndex));
// Merge the move of "9" (assume 9 already removed from right)
right = Lists.newArrayList(6, 2, 3, 1, 0, 4, 7);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(9));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(9));
// Inserted just before "2"
assertSame(Integer.valueOf(1), Integer.valueOf(insertionIndex));
// Merge the move of "0" (assume 0 already removed from right)
right = Lists.newArrayList(6, 9, 2, 3, 1, 4, 7);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
// Inserted just before "4"
assertSame(Integer.valueOf(5), Integer.valueOf(insertionIndex));
// merge the addition of "8"
right = Lists.newArrayList(6, 9, 2, 3, 1, 0, 4, 7);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(8));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(8));
// Inserted just before "9"
assertSame(Integer.valueOf(1), Integer.valueOf(insertionIndex));
@@ -143,15 +135,13 @@ public class DiffUtilTest {
// merge the move of "4" (assume already removed from right)
right = Lists.newArrayList(6, 8, 9, 2, 3, 1, 0);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(4));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(4));
// Inserted just after "3"
assertSame(Integer.valueOf(5), Integer.valueOf(insertionIndex));
// merge the move of "6" (assume already removed from right)
right = Lists.newArrayList(8, 9, 2, 3, 4, 1, 0);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(6));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(6));
// Inserted just after "0"
assertSame(Integer.valueOf(7), Integer.valueOf(insertionIndex));
}
@@ -160,23 +150,20 @@ public class DiffUtilTest {
public void insertionIndexTest2() {
// Try and insert between two lists with no common element
final List<Integer> right = Lists.newArrayList(4, 5, 6);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
// We'll add "0" in right and expect it to be added at the end wherever its location in left
final Integer expectedIndex = Integer.valueOf(right.size());
List<Integer> left = Lists.newArrayList(0, 1, 2, 3);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 0, 2, 3);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 2, 3, 0);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -184,43 +171,36 @@ public class DiffUtilTest {
public void insertionIndexTest3() {
// Try and insert an element before the LCS, LCS being the whole second list
final List<Integer> right = Lists.newArrayList(1, 2, 3);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
// We'll add "0" in right and expect it to be added at the beginning
final Integer expectedIndex = Integer.valueOf(0);
List<Integer> left = Lists.newArrayList(0, 1, 2, 3);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(0, 4, 1, 2, 3);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(4, 0, 1, 2, 3);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(4, 0, 5, 1, 2, 3);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(4, 0, 5, 1, 2, 3, 6);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(4, 0, 5, 1, 6, 2, 3);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(4, 0, 5, 1, 6, 2, 7, 8, 3, 9);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -228,30 +208,27 @@ public class DiffUtilTest {
public void insertionIndexTest4() {
// Try and insert an element before the LCS, LCS being part of the second list
// We'll add "0" in right and expect it to be added just before the LCS
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
List<Integer> left = Lists.newArrayList(0, 1, 2, 3);
List<Integer> right = Lists.newArrayList(4, 1, 2, 3);
// Start of LCS is 1
Integer expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(1)));
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(0, 6, 1, 5, 2, 4, 3);
right = Lists.newArrayList(7, 4, 1, 2, 3, 8);
// Start of LCS is 1
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(1)));
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(5, 0, 6, 7, 1, 2, 4, 3);
right = Lists.newArrayList(7, 4, 1, 2, 9, 3, 8);
// Start of LCS is 7
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(7)));
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -259,43 +236,36 @@ public class DiffUtilTest {
public void insertionIndexTest5() {
// Try and insert an element after the LCS, LCS being the whole second list
final List<Integer> right = Lists.newArrayList(1, 2, 3);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
// We'll add "0" in right and expect it to be added at the end
final Integer expectedIndex = Integer.valueOf(right.size());
List<Integer> left = Lists.newArrayList(1, 2, 3, 0);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 2, 3, 4, 0);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 2, 3, 0, 4);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 2, 3, 5, 0, 4);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(6, 1, 2, 3, 5, 0, 4);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 6, 2, 3, 5, 0, 4);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(9, 1, 6, 2, 7, 8, 3, 5, 0, 4);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -303,30 +273,27 @@ public class DiffUtilTest {
public void insertionIndexTest6() {
// Try and insert an element after the LCS, LCS being part of the second list
// We'll add "0" in right and expect it to be added just after the LCS
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
List<Integer> left = Lists.newArrayList(1, 2, 3, 0);
List<Integer> right = Lists.newArrayList(1, 2, 3, 4);
// End of LCS is 3
Integer expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(3)) + 1);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 5, 2, 4, 3, 6, 0);
right = Lists.newArrayList(8, 1, 2, 3, 4, 7);
// End of LCS is 3
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(3)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 2, 4, 3, 7, 6, 0, 5);
right = Lists.newArrayList(8, 1, 2, 9, 3, 4, 7);
// End of LCS is 7
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(7)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -335,41 +302,36 @@ public class DiffUtilTest {
// Try and insert an element in the middle of the LCS, LCS being the whole second list
// We'll add "0" in right and expect it to be added right after the closest LCS element
final List<Integer> right = Lists.newArrayList(1, 2, 3);
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
List<Integer> left = Lists.newArrayList(1, 0, 2, 3);
// Closest LCS element "before" is 1
int expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(1)) + 1);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 2, 0, 3, 4);
// Closest LCS element "before" is 2
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(2)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 0, 4, 2, 3);
// Closest LCS element "before" is 1
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(1)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(5, 1, 4, 2, 0, 3);
// Closest LCS element "before" is 2
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(2)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(6, 1, 7, 8, 0, 9, 2, 10, 3, 5, 4);
// Closest LCS element "before" is 1
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(1)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -377,22 +339,20 @@ public class DiffUtilTest {
public void insertionIndexTest8() {
// Try and insert an element in the middle of the LCS, LCS being part of the second list
// We'll add "0" in right and expect it to be added right after the closest LCS element
- final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ final Comparison emptyComparison = createEmptyComparison();
List<Integer> left = Lists.newArrayList(1, 2, 0, 3);
List<Integer> right = Lists.newArrayList(1, 2, 3, 4);
// Closest LCS element is 2
Integer expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(2)) + 1);
- int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ int insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
left = Lists.newArrayList(1, 5, 2, 4, 0, 3, 6);
right = Lists.newArrayList(8, 1, 2, 3, 4, 7);
// Closest LCS element is 2
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(2)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
/*
@@ -403,8 +363,7 @@ public class DiffUtilTest {
right = Lists.newArrayList(8, 1, 2, 9, 3, 4, 7);
// Closest LCS element is 3
expectedIndex = Integer.valueOf(right.indexOf(Integer.valueOf(3)) + 1);
- insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, new EqualityHelper(), left, right,
- Integer.valueOf(0));
+ insertionIndex = DiffUtil.findInsertionIndex(emptyComparison, left, right, Integer.valueOf(0));
assertSame(expectedIndex, Integer.valueOf(insertionIndex));
}
@@ -425,4 +384,14 @@ public class DiffUtilTest {
assertEquals(list1.get(i), list2.get(i));
}
}
+
+ /**
+ * Creates and return a new empty {@link Comparison} object with a defaut {@link EMFCompareConfiguration}.
+ *
+ * @return the created {@link Comparison}.
+ */
+ private static Comparison createEmptyComparison() {
+ final Comparison emptyComparison = CompareFactory.eINSTANCE.createComparison();
+ return emptyComparison;
+ }
}

Back to the top