CodebaseMerger { public MergeResult merge(Codebase original, Codebase modified, Codebase destination) { MergeResult.Builder resultBuilder = MergeResult.builder(); File mergedDir = filesystem.getTemporaryDirectory("merged_codebase_"); RepositoryExpression mergedExpression = new RepositoryExpression("merged"); resultBuilder.setMergedCodebase(Codebase.create(mergedDir, "merged", mergedExpression)); Set<String> filesToMerge = Sets.union(findFiles(destination), findFiles(modified)); for (String filename : filesToMerge) { this.generateMergedFile(original, modified, destination, resultBuilder, filename); } MergeResult result = resultBuilder.build(); result.report(ui); return result; } @Inject  CodebaseMerger(Ui ui, FileSystem filesystem, CommandRunner cmd, FileDiffer differ); MergeResult merge(Codebase original, Codebase modified, Codebase destination);  }
@Test public void testMerge() throws Exception { Ui ui = mock(Ui.class); when(orig.path()).thenReturn(new File("orig")); when(dest.path()).thenReturn(new File("dest")); when(mod.path()).thenReturn(new File("mod")); when(fileSystem.exists(origFile)).thenReturn(true); when(fileSystem.exists(destFile)).thenReturn(true); when(fileSystem.exists(modFile)).thenReturn(true); when(fileSystem.findFiles(new File("dest"))).thenReturn(ImmutableSet.of(destFile)); when(fileSystem.findFiles(new File("mod"))).thenReturn(ImmutableSet.of(modFile)); File mergedFile = new File("merged_codebase_7/foo"); List<String> mergeArgs = ImmutableList.of( mergedFile.getAbsolutePath(), origFile.getAbsolutePath(), modFile.getAbsolutePath()); when(cmd.runCommand(mergedCodebaseLocation.getAbsolutePath(), "merge", mergeArgs)) .thenReturn(""); CodebaseMerger merger = new CodebaseMerger(ui, fileSystem, cmd, null); MergeResult result = merger.merge(orig, mod, dest); assertThat(result.mergedFiles()).contains(mergedFile.getAbsolutePath()); assertThat(result.failedFiles()).isEmpty(); verify(fileSystem).makeDirsForFile(mergedFile); verify(fileSystem).copyFile(destFile, mergedFile); verify(cmd).runCommand(mergedCodebaseLocation.getAbsolutePath(), "merge", mergeArgs); verify(ui) .message("Merged codebase generated at: %s", mergedCodebaseLocation.getAbsolutePath()); verify(ui).message("%d files merged successfully. No merge conflicts.", 1); }