in javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java [429:533]
private void testGetFromDiffCacheReturnsChangedFilesSortedByPathForMerge(
MergeCommitStrategy mergeCommitStrategy) throws Exception {
setAsRootCodeOwners(admin);
String file1 = "foo/bar.baz";
String file2 = "foo/baz.bar";
String file3 = "bar/foo.baz";
String file4 = "bar/baz.foo";
String file5 = "baz/foo.bar";
// Create a base change.
Change.Id baseChange =
changeOperations
.newChange()
.branch("master")
.file(file1)
.content("base content")
.file(file3)
.content("base content")
.file(file5)
.content("base content")
.create();
approveAndSubmit(baseChange);
// Create another branch
String branchName = "foo";
BranchInput branchInput = new BranchInput();
branchInput.ref = branchName;
branchInput.revision = projectOperations.project(project).getHead("master").name();
gApi.projects().name(project.get()).branch(branchInput.ref).create(branchInput);
// Create a change in master that touches file1, file3 and file5
Change.Id changeInMaster =
changeOperations
.newChange()
.branch("master")
.file(file1)
.content("master content")
.file(file3)
.content("master content")
.file(file5)
.content("master content")
.create();
approveAndSubmit(changeInMaster);
// Create a change in the other branch and that touches file1, file3, file5 and creates file2,
// file4.
Change.Id changeInOtherBranch =
changeOperations
.newChange()
.branch(branchName)
.file(file1)
.content("other content")
.file(file2)
.content("content")
.file(file3)
.content("other content")
.file(file4)
.content("content")
.file(file5)
.content("other content")
.create();
approveAndSubmit(changeInOtherBranch);
// Create a merge change with a conflict resolution for file1 and file2 with the same content as
// in the other branch (no conflict on file2).
Change.Id mergeChange =
changeOperations
.newChange()
.branch("master")
.mergeOfButBaseOnFirst()
.tipOfBranch("master")
.and()
.tipOfBranch(branchName)
.file(file1)
.content("merged content")
.file(file2)
.content("content")
.file(file3)
.content("merged content")
.file(file4)
.content("content")
.file(file5)
.content("merged content")
.create();
ImmutableList<ChangedFile> changedFilesSet =
changedFiles.getFromDiffCache(
project,
getRevisionResource(Integer.toString(mergeChange.get())).getPatchSet().commitId(),
mergeCommitStrategy);
if (MergeCommitStrategy.ALL_CHANGED_FILES.equals(mergeCommitStrategy)) {
assertThat(changedFilesSet)
.comparingElementsUsing(hasPath())
.containsExactly(file4, file3, file5, file1, file2)
.inOrder();
} else if (MergeCommitStrategy.FILES_WITH_CONFLICT_RESOLUTION.equals(mergeCommitStrategy)) {
assertThat(changedFilesSet)
.comparingElementsUsing(hasPath())
.containsExactly(file3, file5, file1);
} else {
fail("expected merge commit strategy: " + mergeCommitStrategy);
}
}