@Test
public void test() {
List<TypeA> list1 = new ArrayList<TypeA>();
List<TypeA> list2 = new ArrayList<TypeA>();
list1.add(new TypeA(1, 2));
list2.add(new TypeA(1, 2));
list1.add(new TypeA(2, 3));
list2.add(new TypeA(2, 4));
list1.add(new TypeA(3, 4));
list2.add(new TypeA(4, 6));
list1.add(new TypeA(5, 7));
list2.add(new TypeA(5, 8));
list1.add(new TypeA(6, 9));
list2.add(new TypeA(6, 10));
list1.add(new TypeA(7, 11));
list2.add(new TypeA(8, 12));
TypeDiffInstruction<TypeA> diffInstruction = new TypeDiffInstruction<TypeA>() {
public String getSerializerName() {
return "TypeA";
}
@Override
public Object getKey(TypeA object) {
return Integer.valueOf(object.getVal1());
}
};
TypeDiffOperation<TypeA> diffOperation = new TypeDiffOperation<TypeA>(diffInstruction);
TypeDiff<TypeA> typeDiff = diffOperation.performDiff(framework, list1, list2, 2);
Assert.assertEquals(2, typeDiff.getExtraInFrom().size());
Assert.assertTrue(typeDiff.getExtraInFrom().contains(new TypeA(3, 4)));
Assert.assertTrue(typeDiff.getExtraInFrom().contains(new TypeA(7, 11)));
Assert.assertEquals(2, typeDiff.getExtraInTo().size());
Assert.assertTrue(typeDiff.getExtraInTo().contains(new TypeA(4, 6)));
Assert.assertTrue(typeDiff.getExtraInTo().contains(new TypeA(8, 12)));
Assert.assertEquals(3, typeDiff.getDiffObjects().size());
Assert.assertEquals(2, typeDiff.getDiffObjects().get(0).getScore());
Assert.assertEquals(2, typeDiff.getDiffObjects().get(1).getScore());
Assert.assertEquals(2, typeDiff.getDiffObjects().get(2).getScore());
long fromHashTotal = 0;
long toHashTotal = 0;
for (ObjectDiffScore<TypeA> diffScore : typeDiff.getDiffObjects()) {
TypeA type = diffScore.getFrom();
Assert.assertTrue(type.equals(new TypeA(2, 3)) || type.equals(new TypeA(5, 7)) || type.equals(new TypeA(6, 9)));
TypeA toType = diffScore.getTo();
Assert.assertTrue(toType.equals(new TypeA(2, 4)) || toType.equals(new TypeA(5, 8)) || toType.equals(new TypeA(6, 10)));
fromHashTotal += type.hashCode();
toHashTotal += toType.hashCode();
}
Assert.assertEquals(650, fromHashTotal);
Assert.assertEquals(689, toHashTotal);
Assert.assertEquals(2, typeDiff.getSortedFieldDifferencesDescending().size());