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);  }
@Test void mergeCharOnConflicts() throws Exception { MergeResult<Character> result; Conflict<Character> conflict; MergeConfiguration<Character> mergeConfiguration; List<Character> emptyList = Collections.emptyList(); List<Character> onlyA = toCharacters("a"); List<Character> onlyB = toCharacters("b"); List<Character> onlyC = toCharacters("c"); mergeConfiguration = null; result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); conflict = createConflict(0, Type.CHANGE, 0, 0, onlyA, onlyB, Type.CHANGE, 0, 0, onlyA, emptyList); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyB, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyB, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); 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(onlyA, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); 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(emptyList, result.getMerged()); mergeConfiguration = null; result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); conflict = createConflict(0, 'a', 'c', 'b'); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyC, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); 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()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); 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(onlyA, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); 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(onlyB, result.getMerged()); mergeConfiguration = null; 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')); 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())); mergeConfiguration = new MergeConfiguration<>(); 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())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); 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("abcd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); 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("yycd", 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')); mergeConfiguration = null; 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())); mergeConfiguration = new MergeConfiguration<>(); 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())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); 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("abcd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); 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("azzd", 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')); mergeConfiguration = null; 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())); mergeConfiguration = new MergeConfiguration<>(); 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())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); 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("aabbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); 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("arrbcc", 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')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("aabbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("ddddcc", 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')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); List<LogEvent> logConflicts = new ArrayList<>(result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("arrbcc yycd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(logConflicts, result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("arrbcc yycd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(logConflicts, result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("aabbcc abcd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(logConflicts, result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("ddddcc azzd", toString(result.getMerged())); conflict = createConflict(2, Type.CHANGE, 2, 2, Arrays.asList('c'), Arrays.asList('c', 'd'), Type.CHANGE, 2, 2, Arrays.asList('c'), Arrays.asList('d')); conflict1 = createConflict(4, Type.CHANGE, 4, 4, Arrays.asList('f'), Collections.emptyList(), Type.CHANGE, 4, 4, Arrays.asList('f'), Arrays.asList('f')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), 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("abcdehijk", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), 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("abcdehijk", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), 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("abcefhijk", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), 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("abdefgijk", toString(result.getMerged())); mergeConfiguration = null; conflict = createConflict(1, Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i'), Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('j')); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aibc"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aibc"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ajbc"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("abc"), result.getMerged()); mergeConfiguration = null; conflict = createConflict(1, Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i'), Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i', 'j')); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aib"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aib"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aijb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ab"), result.getMerged()); mergeConfiguration = null; conflict = createConflict(1, Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i', 'j'), Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('j')); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aijb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aijb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ajb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ab"), result.getMerged()); conflict = this.createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('y'), Arrays.asList('c'), Type.CHANGE, 0, 0, Arrays.asList('y'), Arrays.asList('b')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("xy"), toCharacters("ab"), toCharacters("ac"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ac"), result.getMerged()); }
@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())); }
@Test void mergeWithEmptyNew() throws Exception { MergeResult<Character> result; result = this.diffManager.merge(toCharacters("a"), toCharacters(""), toCharacters("b"), null); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(toCharacters("b"), result.getMerged()); }
@Test void mergeWhenUserHasChangedAllContent() throws Exception { MergeResult<String> result; result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), Arrays.asList("New content", "That is completely different"), null); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(1, result.getConflicts().size()); Conflict<String> conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("New content", "That is completely different"), Type.CHANGE, 0, 0, Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("New content", "That is completely different"), result.getMerged()); MergeConfiguration<String> mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), Arrays.asList("New content", "That is completely different"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2", "Line 3"), result.getMerged()); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), Arrays.asList("New content", "That is completely different"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), result.getMerged()); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), Collections.emptyList(), null); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList("Line 1", "Line 2", "Line 3"), Collections.emptyList(), Type.CHANGE, 0, 0, Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3")); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Collections.emptyList(), result.getMerged()); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), Collections.emptyList(), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2", "Line 3"), result.getMerged()); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), Collections.emptyList(), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), result.getMerged()); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Collections.emptyList(), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), null); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Type.CHANGE, 0, 0, Arrays.asList("Line 1", "Line 2", "Line 3"), Collections.emptyList()); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), result.getMerged()); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Collections.emptyList(), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2", "Line 3"), result.getMerged()); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Collections.emptyList(), Arrays.asList("Line 1", "Line 2 modified", "Line 3", "Line 4 Added"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).get(0).toString() .contains("Conflict between")); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Collections.emptyList(), result.getMerged()); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("New content", "That is completely different"), Arrays.asList("New content", "That is completely different"), null); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(Arrays.asList("New content", "That is completely different"), result.getMerged()); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager.merge(Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("New content", "That is completely different"), Arrays.asList("New content", "That is completely different"), mergeConfiguration); assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(0, result.getConflicts().size()); assertEquals(Arrays.asList("New content", "That is completely different"), result.getMerged()); mergeConfiguration = null; conflict = this.createConflict(2, Type.CHANGE, 2, 2, Arrays.asList("started to walk"), Arrays.asList("started to walk", "dressed in black"), Type.CHANGE, 2, 2, Arrays.asList("started to walk"), Arrays.asList("dressed in black")); result = this.diffManager .merge( Arrays.asList( "Once upon a time", "a wolf", "started to walk", "in the forest" ), Arrays.asList( "Once upon a time", "a wolf", "dressed in black", "in the forest" ), Arrays.asList( "Once upon a time", "a wolf", "started to walk", "dressed in black", "in the forest" ), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals( Arrays.asList("Once upon a time", "a wolf", "started to walk", "dressed in black", "in the forest"), result.getMerged()); mergeConfiguration = null; conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList("A first edit from a tab."), Arrays.asList("A second edit from another tab.", "Another line"), Type.CHANGE, 0, 0, Arrays.asList("A first edit from a tab."), Arrays.asList("A second edit from another tab.")); result = this.diffManager.merge( Arrays.asList("A first edit from a tab."), Arrays.asList("A second edit from another tab."), Arrays.asList("A second edit from another tab.", "Another line"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("A second edit from another tab.", "Another line"), result.getMerged()); conflict = this.createConflict(0, Type.CHANGE, 0, 0, Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ), Arrays.asList( "A sixth edit from the first tab.", "Another line.", "Yet another line edited from the first tab." ), Type.CHANGE, 0, 0, Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ), Arrays.asList( "A sixth edit from the second tab.", "Another line with small changes.", "Another edit from the second tab." )); result = this.diffManager.merge( Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ), Arrays.asList( "A sixth edit from the second tab.", "Another line with small changes.", "Another edit from the second tab." ), Arrays.asList( "A sixth edit from the first tab.", "Another line.", "Yet another line edited from the first tab." ), mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); conflict = this.createConflict(0, Type.CHANGE, 0, 0, Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ), Arrays.asList( "A sixth edit from the first tab.", "Another line.", "Yet another line edited from the first tab." ), Type.CHANGE, 0, 0, Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ), Collections.emptyList()); result = this.diffManager.merge( Arrays.asList( "A fifth edit from another tab.", "Another line.", "Yet another line with other few changes." ), Collections.emptyList(), Arrays.asList( "A sixth edit from the first tab.", "Another line.", "Yet another line edited from the first tab." ), mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); conflict = this.createConflict(0, Type.CHANGE, 0, 0, Arrays.asList("Some content."), Arrays.asList("Another content", "On multiple lines."), Type.CHANGE, 0, 0, Arrays.asList("Some content."), Arrays.asList( "Some content.", "", "And now if I try", "to put something", "", "with empty lines", "like this" )); result = this.diffManager.merge( Arrays.asList( "Some content." ), Arrays.asList( "Some content.", "", "And now if I try", "to put something", "", "with empty lines", "like this" ), Arrays.asList( "Another content", "On multiple lines." ), mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); conflict = this.createConflict(1, Type.CHANGE, 1, 1, Arrays.asList("Second line.", "Third line."), Arrays.asList("Second line.", "Line N°4"), Type.CHANGE, 1, 1, Arrays.asList("Second line.", "Third line."), Arrays.asList("Line N°2", "Third line.")); Conflict<String> conflict2 = this.createConflict(5, Type.CHANGE, 5, 5, Collections.emptyList(), Arrays.asList("6th line."), Type.CHANGE, 5, 5, Collections.emptyList(), Arrays.asList("Sixth line.")); result = this.diffManager.merge( Arrays.asList( "First line.", "Second line.", "Third line.", "Fourth line.", "Fifth line.", "Seventh line." ), Arrays.asList( "First line.", "Line N°2", "Third line.", "Fifth line.", "Sixth line.", "Seventh line." ), Arrays.asList( "First line.", "Second line.", "Line N°4", "Fifth line.", "6th line.", "Seventh line." ), mergeConfiguration); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict2, result.getConflicts().get(1)); assertEquals(Arrays.asList( "First line.", "Second line.", "Line N°4", "Fifth line.", "6th line.", "Seventh line." ), result.getMerged()); conflict = this.createConflict(0, Type.CHANGE, 0, 0, Arrays.asList("A second edit from another tab.", "A new line."), Arrays.asList("A fourth edit from second tab.", "Another line."), Type.CHANGE, 0, 0, Arrays.asList("A second edit from another tab.", "A new line."), Arrays.asList("A third edit from another tab.", "Another line.", "Yet another line.")); result = this.diffManager.merge( Arrays.asList("A second edit from another tab.", "A new line."), Arrays.asList("A third edit from another tab.", "Another line.", "Yet another line."), Arrays.asList("A fourth edit from second tab.", "Another line."), mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); mergeConfiguration = null; conflict = this.createConflict(1, Type.CHANGE, 1, 1, Arrays.asList("Anything else"), Arrays.asList("", "And now if I try", "to put something", "", "with empty lines", "like this"), Type.CHANGE, 1, 1, Arrays.asList("Anything else"), Arrays.asList("On multiple lines.")); result = diffManager.merge(Arrays.asList( "Some content.", "Anything else" ), Arrays.asList( "Some content.", "On multiple lines." ), Arrays.asList( "Some content.", "", "And now if I try", "to put something", "", "with empty lines", "like this" ), mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); }
@Test void applyDecisionsOnLinesConflicts() throws Exception { MergeResult<String> result; MergeConfiguration<String> mergeConfiguration; result = diffManager.merge( Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Arrays.asList("Line 1", "Line 2 another change", "Line 3"), null); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); Conflict<String> conflict = createConflict(1, "Line 2", "Line 2 another change", "Line 2 modified"); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2 another change", "Line 3"), result.getMerged()); ConflictDecision<String> conflictDecision = new DefaultConflictDecision<>(conflict); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); List<ConflictDecision<String>> conflictDecisionList = new ArrayList<>(); conflictDecisionList.add(conflictDecision); mergeConfiguration = new MergeConfiguration<>(conflictDecisionList); result = diffManager.merge( Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Arrays.asList("Line 1", "Line 2 another change", "Line 3"), mergeConfiguration); assertTrue(result.getConflicts().isEmpty()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).isEmpty()); assertEquals(Arrays.asList("Line 1", "Line 2", "Line 3"), result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.NEXT); result = diffManager.merge( Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Arrays.asList("Line 1", "Line 2 another change", "Line 3"), mergeConfiguration); assertTrue(result.getConflicts().isEmpty()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).isEmpty()); assertEquals(Arrays.asList("Line 1", "Line 2 modified", "Line 3"), result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.CURRENT); result = diffManager.merge( Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Arrays.asList("Line 1", "Line 2 another change", "Line 3"), mergeConfiguration); assertTrue(result.getConflicts().isEmpty()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).isEmpty()); assertEquals(Arrays.asList("Line 1", "Line 2 another change", "Line 3"), result.getMerged()); conflictDecision.setType(ConflictDecision.DecisionType.UNDECIDED); result = diffManager.merge( Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Arrays.asList("Line 1", "Line 2 another change", "Line 3"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(Arrays.asList("Line 1", "Line 2 another change", "Line 3"), result.getMerged()); conflictDecision.setCustom(Arrays.asList("Another complete custom change", "and a line")); result = diffManager.merge( Arrays.asList("Line 1", "Line 2", "Line 3"), Arrays.asList("Line 1", "Line 2 modified", "Line 3"), Arrays.asList("Line 1", "Line 2 another change", "Line 3"), mergeConfiguration); assertTrue(result.getConflicts().isEmpty()); assertTrue(result.getLog().getLogs(LogLevel.ERROR).isEmpty()); assertEquals(Arrays.asList("Line 1", "Another complete custom change", "and a line", "Line 3"), result.getMerged()); conflictDecisionList = new ArrayList<>(); conflict = this.createConflict(1, Type.CHANGE, 1, 1, Arrays.asList("Second line.", "Third line."), Arrays.asList("Second line.", "Line N°4"), Type.CHANGE, 1, 1, Arrays.asList("Second line.", "Third line."), Arrays.asList("Line N°2", "Third line.")); conflictDecision = new DefaultConflictDecision<>(conflict); conflictDecision.setCustom(Arrays.asList("Something", "Completely", "Different")); conflictDecisionList.add(conflictDecision); Conflict<String> conflict2 = this.createConflict(5, Type.CHANGE, 5, 5, Collections.emptyList(), Arrays.asList("6th line."), Type.CHANGE, 5, 5, Collections.emptyList(), Arrays.asList("Sixth line.")); conflictDecision = new DefaultConflictDecision<>(conflict2); conflictDecision.setType(ConflictDecision.DecisionType.PREVIOUS); conflictDecisionList.add(conflictDecision); mergeConfiguration = new MergeConfiguration<>(conflictDecisionList); result = this.diffManager.merge( Arrays.asList( "First line.", "Second line.", "Third line.", "Fourth line.", "Fifth line.", "Seventh line." ), Arrays.asList( "First line.", "Line N°2", "Third line.", "Fifth line.", "Sixth line.", "Seventh line." ), Arrays.asList( "First line.", "Second line.", "Line N°4", "Fifth line.", "6th line.", "Seventh line." ), mergeConfiguration); assertEquals(0, result.getConflicts().size()); assertEquals(Arrays.asList( "First line.", "Something", "Completely", "Different", "Fifth line.", "Seventh line." ), result.getMerged()); }