### Question:
VectorClockInconsistencyResolver implements IInconsistencyResolver<Versioned<T>> { public List<Versioned<T>> resolveConflicts(List<Versioned<T>> items) { int size = items.size(); if(size <= 1) return items; List<Versioned<T>> newItems = Lists.newArrayList(); for(Versioned<T> v1: items) { boolean found = false; for(ListIterator<Versioned<T>> it2 = newItems.listIterator(); it2.hasNext();) { Versioned<T> v2 = it2.next(); Occurred compare = v1.getVersion().compare(v2.getVersion()); if(compare == Occurred.AFTER) { if(found) it2.remove(); else it2.set(v1); } if(compare != Occurred.CONCURRENTLY) found = true; } if(!found) newItems.add(v1); } return newItems; }  List<Versioned<T>> resolveConflicts(List<Versioned<T>> items); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@SuppressWarnings("unchecked") @Test public void testResolveNormal() { assertEquals(later, resolver.resolveConflicts(Arrays.asList(current, prior, later)).get(0)); assertEquals(later, resolver.resolveConflicts(Arrays.asList(prior, current, later)).get(0)); assertEquals(later, resolver.resolveConflicts(Arrays.asList(later, current, prior)).get(0)); }
@SuppressWarnings("unchecked") @Test public void testResolveConcurrent() { List<Versioned<String>> resolved = resolver.resolveConflicts(Arrays.asList(current, concurrent, prior)); assertEquals(2, resolved.size()); assertTrue("Version not found", resolved.contains(current)); assertTrue("Version not found", resolved.contains(concurrent)); }
@SuppressWarnings("unchecked") @Test public void testResolveLargerConcurrent() { assertEquals(3, resolver.resolveConflicts(Arrays.asList(concurrent, concurrent2, current, concurrent2, current, concurrent, current)).size()); }
@SuppressWarnings("unchecked") @Test public void testResolveConcurrentPairWithLater() { Versioned<String> later2 = getVersioned(1, 2, 3, 3, 4, 4); List<Versioned<String>> resolved = resolver.resolveConflicts(Arrays.asList(concurrent, concurrent2, later2)); assertEquals(1, resolved.size()); assertEquals(later2, resolved.get(0)); }
@Test public void testEmptyList() { assertEquals(0, resolver.resolveConflicts(new ArrayList<Versioned<String>>()).size()); }
@SuppressWarnings("unchecked") @Test public void testDuplicatesResolve() { assertEquals(2, resolver.resolveConflicts(Arrays.asList(concurrent, current, current, concurrent, current)).size()); }