/**
* Test for merge()
*/
public void testMerge() throws Exception {
Ui ui = control.createMock(Ui.class);
AppContext.RUN.ui = ui;
File mergedCodebaseLocation = new File("merged_codebase_7");
expect(fileSystem.getTemporaryDirectory("merged_codebase_")).andReturn(mergedCodebaseLocation);
expect(dest.getRelativeFilenames()).andReturn(ImmutableSet.of("foo"));
expect(mod.getRelativeFilenames()).andReturn(ImmutableSet.of("foo", "bar"));
// generateMergedFile(...) on foo
File origFile = new File("orig/foo");
expect(orig.getFile("foo")).andReturn(origFile);
expect(fileSystem.exists(origFile)).andReturn(true);
File destFile = new File("dest/foo");
expect(dest.getFile("foo")).andReturn(destFile);
expect(fileSystem.exists(destFile)).andReturn(true);
File modFile = new File("mod/foo");
expect(mod.getFile("foo")).andReturn(modFile);
expect(fileSystem.exists(modFile)).andReturn(true);
File mergedFile = new File("merged_codebase_7/foo");
fileSystem.makeDirsForFile(mergedFile);
fileSystem.copyFile(destFile, mergedFile);
List<String> mergeArgs = ImmutableList.of(mergedFile.getAbsolutePath(),
origFile.getAbsolutePath(), modFile.getAbsolutePath());
expect(cmd.runCommand("merge", mergeArgs,
mergedCodebaseLocation.getAbsolutePath())).andReturn("");
// generateMergedFile(...) on bar
origFile = new File("orig/bar");
expect(orig.getFile("bar")).andReturn(origFile);
expect(fileSystem.exists(origFile)).andReturn(true);
destFile = new File("dest/bar");
expect(dest.getFile("bar")).andReturn(destFile);
expect(fileSystem.exists(destFile)).andReturn(true);
modFile = new File("mod/bar");
expect(mod.getFile("bar")).andReturn(modFile);
expect(fileSystem.exists(modFile)).andReturn(false);
// No merging of bar, just follow deletion of origFile by not copying destFile to merged
// codebase.
// Expect in call to report()
ui.info("Merged codebase generated at: " + mergedCodebaseLocation.getAbsolutePath());
ui.info(String.format(
"%d files merged successfully%n" +
"%d files have merge conflicts. Edit the following files to resolve conflicts:%n%s",
1, 0, ImmutableSet.of()));
control.replay();