@Test void applyDecisionsOnMergeCharConflicts() throws Exception { MergeResult<Character> result; MergeConfiguration<Character> mergeConfiguration; Conflict<Character> conflict; ConflictDecision<Character> conflictDecision; List<ConflictDecision<Character>> allConflictDecisions; List<Character> emptyList = Collections.emptyList(); List<Character> onlyA = toCharacters("a"); List<Character> onlyB = toCharacters("b"); List<Character> onlyC = toCharacters("c"); conflict = createConflict(0, Type.CHANGE, 0, 0, onlyA, onlyB, Type.CHANGE, 0, 0, onlyA, emptyList); conflictDecision = new DefaultConflictDecision<>(conflict); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); allConflictDecisions = Collections.singletonList(conflictDecision); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyB, result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(onlyB, result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(onlyA, result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(emptyList, result.getMerged()); conflictDecision.setCustom(Arrays.asList('x', 'y')); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(Arrays.asList('x', 'y'), result.getMerged()); conflict = createConflict(0, 'a', 'c', 'b'); conflictDecision = new DefaultConflictDecision<>(conflict); allConflictDecisions = Collections.singletonList(conflictDecision); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyC, result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(onlyC, result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(onlyA, result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(onlyB, result.getMerged()); conflictDecision.setCustom(Collections.emptyList()); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(Collections.emptyList(), result.getMerged()); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('a', 'z'), Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('y', 'y')); conflictDecision = new DefaultConflictDecision<>(conflict); allConflictDecisions = Collections.singletonList(conflictDecision); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("azzd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("azzd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("yycd", toString(result.getMerged())); conflictDecision.setCustom(toCharacters("Something else")); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("Something elsed", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('y', 'y'), Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('a', 'z')); conflictDecision = new DefaultConflictDecision<>(conflict); allConflictDecisions = Collections.singletonList(conflictDecision); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("azzd", toString(result.getMerged())); conflictDecision.setCustom(Collections.singletonList('x')); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("xd", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('d', 'd', 'd', 'd'), Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('a', 'r', 'r', 'b')); conflictDecision = new DefaultConflictDecision<>(conflict); allConflictDecisions = Collections.singletonList(conflictDecision); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("ddddcc", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("ddddcc", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("aabbcc", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("arrbcc", toString(result.getMerged())); conflictDecision.setCustom(toCharacters("anything")); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("anythingcc", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('a', 'r', 'r', 'b'), Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('d', 'd', 'd', 'd')); conflictDecision = new DefaultConflictDecision<>(conflict); allConflictDecisions = Collections.singletonList(conflictDecision); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("arrbcc", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("aabbcc", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("ddddcc", toString(result.getMerged())); conflictDecision.setCustom(Collections.emptyList()); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("cc", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('a', 'r', 'r', 'b'), Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('d', 'd', 'd', 'd')); Conflict<Character> conflict1 = createConflict(7, Type.CHANGE, 7, 7, Arrays.asList('a', 'b'), Arrays.asList('y', 'y'), Type.CHANGE, 7, 7, Arrays.asList('a', 'b'), Arrays.asList('a', 'z')); allConflictDecisions = new ArrayList<>(); conflictDecision = new DefaultConflictDecision<>(conflict); allConflictDecisions.add(conflictDecision); ConflictDecision<Character> conflictDecision1 = new DefaultConflictDecision<>(conflict1); allConflictDecisions.add(conflictDecision1); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); conflictDecision1.setType(ConflictDecision.DecisionType.UNDECIDED); mergeConfiguration = new MergeConfiguration<>(allConflictDecisions); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("arrbcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); conflictDecision1.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("arrbcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); conflictDecision1.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("aabbcc abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); conflictDecision1.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("ddddcc azzd", toString(result.getMerged())); conflictDecision.setCustom(toCharacters("A first change")); conflictDecision1.setCustom(toCharacters("and another one")); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("A first changecc and another oned", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); conflictDecision1.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("arrbcc azzd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); conflictDecision1.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("ddddcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); conflictDecision1.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("arrbcc abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); conflictDecision1.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("aabbcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); conflictDecision1.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("ddddcc abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); conflictDecision1.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("aabbcc azzd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); conflictDecision1.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); conflictDecision1.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict1, result.getConflicts().get(0)); assertEquals("arrbcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); conflictDecision1.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); conflictDecision1.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict1, result.getConflicts().get(0)); assertEquals("aabbcc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); conflictDecision1.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc azzd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); conflictDecision1.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict1, result.getConflicts().get(0)); assertEquals("ddddcc yycd", toString(result.getMerged())); conflictDecision.setCustom(toCharacters("bla")); conflictDecision1.setType(ConflictDecision.DecisionType.UNDECIDED); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict1, result.getConflicts().get(0)); assertEquals("blacc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); conflictDecision1.setCustom(toCharacters("foo")); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc food", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CUSTOM); conflictDecision1.setType(ConflictDecision.DecisionType.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("cc azzd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); conflictDecision1.setCustom(toCharacters("foobar")); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("ddddcc foobard", toString(result.getMerged())); conflictDecision.setCustom(toCharacters("Something like that")); conflictDecision1.setType(ConflictDecision.DecisionType.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("Something like thatcc abcd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); conflictDecision1.setCustom(toCharacters("dddddd")); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("aabbcc ddddddd", toString(result.getMerged())); conflictDecision.setCustom(toCharacters("abc")); conflictDecision1.setType(ConflictDecision.DecisionType.CURRENT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("abccc yycd", toString(result.getMerged())); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); conflictDecision1.setCustom(toCharacters("azzd")); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals("arrbcc azzdd", toString(result.getMerged())); }
@Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; } }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }  }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }  @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); }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }  @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);  }