CookbookDiff { public List diff(final String oldText, final String newText) { Node.panchor = null; oldInfo = new SourceInfo(); newInfo = new SourceInfo(); inputScan(oldText, oldInfo); inputScan(newText, newInfo); oldInfo.alloc(); newInfo.alloc(); blocklen = new int[(oldInfo.maxLine > newInfo.maxLine ? oldInfo.maxLine : newInfo.maxLine) + 2]; transform(); return printOut(); }  List diff(final String oldText, final String newText); static final int idle; }
@Test public void testAddText() { final String text1 = "Line1\nLine2\nDies ist ein Text."; final String text2 = text1 + "Text2"; final List diffList = differenceService.diff(text1, text2); final int i = 1; for (final Iterator iter = diffList.iterator(); iter.hasNext();) { final ChangeInfo changeInfo = (ChangeInfo) iter.next(); assertEquals("Type must be CHANGE", changeInfo.getType(), ChangeInfo.CHANGE); assertEquals("Wrong line content.", changeInfo.getLines()[0], "Dies ist ein Text."); assertEquals("Wrong line content.", changeInfo.getLines()[1], "Dies ist ein Text.Text2"); } }
@Test public void testMove() { final String text1 = "Line1\nLine2\nDies ist ein Text.\nbla bla\nText2 Text2.1 Text2.2"; final String text2 = "Line1\nLine2\nDies ist ein Text.\nText2 Text2.1 Text2.2\nbla bla"; final List diffList = differenceService.diff(text1, text2); final int i = 1; for (final Iterator iter = diffList.iterator(); iter.hasNext();) { final ChangeInfo changeInfo = (ChangeInfo) iter.next(); assertEquals("Type must be MOVE", changeInfo.getType(), ChangeInfo.MOVE); assertEquals("Wrong line content.", changeInfo.getLines()[0], "Text2 Text2.1 Text2.2"); } }