DefaultUnifiedDiffDisplayer implements UnifiedDiffDisplayer { @Override public <E, F> List<UnifiedDiffBlock<E, F>> display(DiffResult<E> diffResult) { return display(diffResult, this.<E, F>getDefaultConfiguration()); }  @Override UnifiedDiffConfiguration<E, F> getDefaultConfiguration(); @Override List<UnifiedDiffBlock<E, F>> display(DiffResult<E> diffResult); @Override List<UnifiedDiffBlock<E, F>> display(DiffResult<E> diffResult, List<Conflict<E>> conflicts); @Override List<UnifiedDiffBlock<E, F>> display(DiffResult<E> diffResult, UnifiedDiffConfiguration<E, F> config); @Override List<UnifiedDiffBlock<E, F>> display(DiffResult<E> diffResult, List<Conflict<E>> conflicts,
        UnifiedDiffConfiguration<E, F> config);  }
@Test void displayWithConflicts() throws Exception { List<String> previous = readLines("previous.txt"); List<String> current = readLines("twoContexts.txt"); List<String> next = readLines("twoContexts_next.txt"); MergeResult<String> mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); DiffResult<String> diffResult = getDiffManager().diff(previous, next, null); List<UnifiedDiffBlock<String, Object>> unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(2, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); assertFalse(unifiedDiffBlocks.get(1).isConflicting()); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(4, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); assertFalse(unifiedDiffBlocks.get(1).isConflicting()); assertTrue(unifiedDiffBlocks.get(2).isConflicting()); assertFalse(unifiedDiffBlocks.get(3).isConflicting()); assertEquals(3, unifiedDiffBlocks.get(1).size()); assertEquals(2, unifiedDiffBlocks.get(2).size()); UnifiedDiffConflictElement<String> unifiedDiffConflictElement = unifiedDiffBlocks.get(2).getConflict(); assertEquals(Collections.singletonList(" unifiedDiffConflictElement.getPreviousElement()); assertEquals(Collections.singletonList(" unifiedDiffConflictElement.getCurrentElement()); assertEquals(Collections.singletonList(" unifiedDiffConflictElement.getNextElement()); }
@Test void displayWithConflictsMultipleLines() throws Exception { List<String> previous = Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ); List<String> next = Arrays.asList( "A sixth edit from the second tab.", "Another line with small changes.", "Another edit from the second tab." ); List<String> current = Arrays.asList( "A sixth edit from the first tab.", "Another line.", "Yet another line edited from the first tab." ); MergeResult<String> mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); DiffResult<String> diffResult = getDiffManager().diff(next, current, null); List<UnifiedDiffBlock<String, Object>> unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); List<UnifiedDiffBlock<String, Object>> unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(1, unifiedDiffBlocksWithConflicts.size()); assertTrue(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); UnifiedDiffConflictElement<String> conflict = unifiedDiffBlocksWithConflicts.get(0).getConflict(); assertEquals(previous, conflict.getPreviousElement()); assertEquals(next, conflict.getNextElement()); assertEquals(current, conflict.getCurrentElement()); previous = Arrays.asList( "Some content." ); next = Arrays.asList( "Some content.", "", "And now if I try", "to put something", "", "with empty lines", "like this" ); current = Arrays.asList( "Another content", "On multiple lines." ); mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); diffResult = getDiffManager().diff(next, current, null); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(1, unifiedDiffBlocksWithConflicts.size()); assertTrue(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); assertEquals(9, unifiedDiffBlocksWithConflicts.get(0).size()); assertEquals(previous, unifiedDiffBlocksWithConflicts.get(0).getConflict().getPreviousElement()); assertEquals(next, unifiedDiffBlocksWithConflicts.get(0).getConflict().getNextElement()); assertEquals(current, unifiedDiffBlocksWithConflicts.get(0).getConflict().getCurrentElement()); previous = Arrays.asList( "Some content.", "Anything else" ); next = Arrays.asList( "Some content.", "On multiple lines." ); current = Arrays.asList( "Some content.", "", "And now if I try", "to put something", "", "with empty lines", "like this" ); mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); diffResult = getDiffManager().diff(next, current, null); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(2, unifiedDiffBlocksWithConflicts.size()); assertFalse(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); assertTrue(unifiedDiffBlocksWithConflicts.get(1).isConflicting()); assertEquals(1, unifiedDiffBlocksWithConflicts.get(0).size()); assertEquals(" Some content.\n", unifiedDiffBlocksWithConflicts.get(0).get(0).toString()); assertEquals(7, unifiedDiffBlocksWithConflicts.get(1).size()); assertEquals("-On multiple lines.\n", unifiedDiffBlocksWithConflicts.get(1).get(0).toString()); assertEquals("+\n", unifiedDiffBlocksWithConflicts.get(1).get(1).toString()); assertEquals("+And now if I try\n", unifiedDiffBlocksWithConflicts.get(1).get(2).toString()); assertEquals("+to put something\n", unifiedDiffBlocksWithConflicts.get(1).get(3).toString()); assertEquals("+\n", unifiedDiffBlocksWithConflicts.get(1).get(4).toString()); assertEquals("+with empty lines\n", unifiedDiffBlocksWithConflicts.get(1).get(5).toString()); assertEquals("+like this\n", unifiedDiffBlocksWithConflicts.get(1).get(6).toString()); previous = Arrays.asList( "Some content.", "Anything else" ); next = Arrays.asList( "Some content.", "", "And now if I try", "to put something", "", "with empty lines", "like this" ); current = Arrays.asList( "Some content.", "On multiple lines." ); mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); diffResult = getDiffManager().diff(next, current, null); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(2, unifiedDiffBlocksWithConflicts.size()); assertFalse(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); assertTrue(unifiedDiffBlocksWithConflicts.get(1).isConflicting()); assertEquals(1, unifiedDiffBlocksWithConflicts.get(0).size()); assertEquals(" Some content.\n", unifiedDiffBlocksWithConflicts.get(0).get(0).toString()); assertEquals(7, unifiedDiffBlocksWithConflicts.get(1).size()); assertEquals("-\n", unifiedDiffBlocksWithConflicts.get(1).get(0).toString()); assertEquals("-And now if I try\n", unifiedDiffBlocksWithConflicts.get(1).get(1).toString()); assertEquals("-to put something\n", unifiedDiffBlocksWithConflicts.get(1).get(2).toString()); assertEquals("-\n", unifiedDiffBlocksWithConflicts.get(1).get(3).toString()); assertEquals("-with empty lines\n", unifiedDiffBlocksWithConflicts.get(1).get(4).toString()); assertEquals("-like this\n", unifiedDiffBlocksWithConflicts.get(1).get(5).toString()); assertEquals("+On multiple lines.\n", unifiedDiffBlocksWithConflicts.get(1).get(6).toString()); previous = Arrays.asList( "First line.", "Second line.", "Third line.", "Fourth line.", "Fifth line.", "Seventh line." ); next = Arrays.asList( "First line.", "Line N°2", "Third line.", "Fifth line.", "Sixth line.", "Seventh line." ); current = Arrays.asList( "First line.", "Second line.", "Line N°4", "Fifth line.", "6th line.", "Seventh line." ); mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(2, mergeResult.getConflicts().size()); diffResult = getDiffManager().diff(next, current, null); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); assertFalse(unifiedDiffBlocks.get(0).isConflicting()); unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(5, unifiedDiffBlocksWithConflicts.size()); assertFalse(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); assertTrue(unifiedDiffBlocksWithConflicts.get(1).isConflicting()); assertFalse(unifiedDiffBlocksWithConflicts.get(2).isConflicting()); assertTrue(unifiedDiffBlocksWithConflicts.get(3).isConflicting()); assertFalse(unifiedDiffBlocksWithConflicts.get(4).isConflicting()); assertEquals(1, unifiedDiffBlocksWithConflicts.get(0).size()); assertEquals(" First line.\n", unifiedDiffBlocksWithConflicts.get(0).get(0).toString()); assertEquals(4, unifiedDiffBlocksWithConflicts.get(1).size()); assertEquals("-Line N°2\n", unifiedDiffBlocksWithConflicts.get(1).get(0).toString()); assertEquals("-Third line.\n", unifiedDiffBlocksWithConflicts.get(1).get(1).toString()); assertEquals("+Second line.\n", unifiedDiffBlocksWithConflicts.get(1).get(2).toString()); assertEquals("+Line N°4\n", unifiedDiffBlocksWithConflicts.get(1).get(3).toString()); assertEquals(1, unifiedDiffBlocksWithConflicts.get(2).size()); assertEquals(" Fifth line.\n", unifiedDiffBlocksWithConflicts.get(2).get(0).toString()); assertEquals(2, unifiedDiffBlocksWithConflicts.get(3).size()); assertEquals("-Sixth line.\n", unifiedDiffBlocksWithConflicts.get(3).get(0).toString()); assertEquals("+6th line.\n", unifiedDiffBlocksWithConflicts.get(3).get(1).toString()); assertEquals(1, unifiedDiffBlocksWithConflicts.get(4).size()); assertEquals(" Seventh line.\n", unifiedDiffBlocksWithConflicts.get(4).get(0).toString()); previous = Arrays.asList("Foo", "Bar", "Baz"); current = Arrays.asList("Some", "Other", "Thing"); next = Arrays.asList("Any", "Other", "Thing"); mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); diffResult = getDiffManager().diff(previous, next, null); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(2, unifiedDiffBlocksWithConflicts.size()); assertTrue(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); assertFalse(unifiedDiffBlocksWithConflicts.get(1).isConflicting()); assertEquals(2, unifiedDiffBlocksWithConflicts.get(0).size()); assertEquals(4, unifiedDiffBlocksWithConflicts.get(1).size()); assertEquals("-Foo\n", unifiedDiffBlocksWithConflicts.get(0).get(0).toString()); assertEquals("+Any\n", unifiedDiffBlocksWithConflicts.get(0).get(1).toString()); assertEquals("-Bar\n", unifiedDiffBlocksWithConflicts.get(1).get(0).toString()); assertEquals("-Baz\n", unifiedDiffBlocksWithConflicts.get(1).get(1).toString()); assertEquals("+Other\n", unifiedDiffBlocksWithConflicts.get(1).get(2).toString()); assertEquals("+Thing\n", unifiedDiffBlocksWithConflicts.get(1).get(3).toString()); previous = Arrays.asList("Foo", "Bar", "Baz"); current = Arrays.asList("Other"); next = Arrays.asList("Other", "Thing"); mergeResult = getDiffManager().merge(previous, next, current, null); assertEquals(1, mergeResult.getConflicts().size()); diffResult = getDiffManager().diff(previous, next, null); unifiedDiffBlocks = unifiedDiffDisplayer.display(diffResult); assertEquals(1, unifiedDiffBlocks.size()); unifiedDiffBlocksWithConflicts = unifiedDiffDisplayer.display(diffResult, mergeResult.getConflicts()); assertEquals(2, unifiedDiffBlocksWithConflicts.size()); assertTrue(unifiedDiffBlocksWithConflicts.get(0).isConflicting()); assertFalse(unifiedDiffBlocksWithConflicts.get(1).isConflicting()); assertEquals(4, unifiedDiffBlocksWithConflicts.get(0).size()); assertEquals(1, unifiedDiffBlocksWithConflicts.get(1).size()); assertEquals("-Foo\n", unifiedDiffBlocksWithConflicts.get(0).get(0).toString()); assertEquals("-Bar\n", unifiedDiffBlocksWithConflicts.get(0).get(1).toString()); assertEquals("+Other\n", unifiedDiffBlocksWithConflicts.get(0).get(2).toString()); assertEquals("+Thing\n", unifiedDiffBlocksWithConflicts.get(0).get(3).toString()); assertEquals("-Baz\n", unifiedDiffBlocksWithConflicts.get(1).get(0).toString()); }