DefaultDiffManager implements DiffManager { @Override public <E> DiffResult<E> diff(List<E> previous, List<E> next, DiffConfiguration<E> diff) throws DiffException { DefaultDiffResult<E> result = new DefaultDiffResult<>(previous, next); Patch<E> patch; if (previous == null || previous.isEmpty()) { patch = new DefaultPatch<>(); if (next != null && !next.isEmpty()) { patch.add(new InsertDelta<>(new DefaultChunk<>(0, Collections.emptyList()), new DefaultChunk<>(0, next))); } } else if (next == null || next.isEmpty()) { patch = new DefaultPatch<>(); patch.add(new DeleteDelta<>(new DefaultChunk<>(0, previous), new DefaultChunk<>(0, Collections.emptyList()))); } else { patch = new DefaultPatch<>(DiffUtils.diff(previous, next)); } result.setPatch(patch); return result; }  @Override DiffResult<E> diff(List<E> previous, List<E> next, DiffConfiguration<E> diff); @Override MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current,
        MergeConfiguration<E> configuration);  }
@Test void diffStringList() throws Exception { DiffResult<String> result = this.diffManager.diff(null, null, null); assertTrue(result.getPatch().isEmpty()); result = this.diffManager.diff(Collections.<String>emptyList(), Collections.<String>emptyList(), null); assertTrue(result.getPatch().isEmpty()); result = this.diffManager.diff(Arrays.asList("equals"), Arrays.asList("equals"), null); assertTrue(result.getPatch().isEmpty()); result = this.diffManager.diff(Collections.<String>emptyList(), Arrays.asList("next"), null); assertEquals(1, result.getPatch().size()); assertEquals(Type.INSERT, result.getPatch().get(0).getType()); assertEquals(Arrays.asList("next"), result.getPatch().get(0).getNext().getElements()); assertEquals(0, result.getPatch().get(0).getNext().getIndex()); result = this.diffManager.diff(Arrays.asList("previous"), Collections.<String>emptyList(), null); assertEquals(1, result.getPatch().size()); assertEquals(Type.DELETE, result.getPatch().get(0).getType()); assertEquals(Arrays.asList("previous"), result.getPatch().get(0).getPrevious().getElements()); assertEquals(0, result.getPatch().get(0).getPrevious().getIndex()); }
@Test void diffCharList() throws Exception { DiffResult<Character> result = this.diffManager.diff(Arrays.asList('a'), Arrays.asList('a'), null); assertTrue(result.getPatch().isEmpty()); result = this.diffManager.diff(Arrays.asList('a'), Arrays.asList('b'), null); assertEquals(1, result.getPatch().size()); assertEquals(Type.CHANGE, result.getPatch().get(0).getType()); }