in javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetCodeOwnerStatusIT.java [87:223]
public void getStatusWithStart() throws Exception {
TestAccount user2 = accountCreator.user2();
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch("master")
.folderPath("/foo/")
.addCodeOwnerEmail(user.email())
.create();
String path1 = "/foo/bar/baz.md";
String path2 = "/foo/baz/bar.md";
String path3 = "/bar/foo.md";
String path4 = "/bar/baz.md";
PushOneCommit.Result r =
createChange(
"Change Adding A File",
ImmutableMap.of(
JgitPath.of(path1).get(),
"file content",
JgitPath.of(path2).get(),
"file content",
JgitPath.of(path3).get(),
"file content",
JgitPath.of(path4).get(),
"file content"));
String changeId = r.getChangeId();
// Add a reviewer that is a code owner.
gApi.changes().id(changeId).addReviewer(user.email());
// Add a Code-Review+1 (= code owner approval) from a user that is not a code owner.
requestScopeOperations.setApiUser(user2.id());
recommend(changeId);
CodeOwnerStatusInfo codeOwnerStatus =
changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withStart(0).get();
assertThat(codeOwnerStatus)
.hasPatchSetNumberThat()
.isEqualTo(r.getChange().currentPatchSet().id().get());
assertThat(codeOwnerStatus)
.hasFileCodeOwnerStatusesThat()
.comparingElementsUsing(isFileCodeOwnerStatus())
.containsExactly(
FileCodeOwnerStatus.addition(path4, CodeOwnerStatus.INSUFFICIENT_REVIEWERS),
FileCodeOwnerStatus.addition(path3, CodeOwnerStatus.INSUFFICIENT_REVIEWERS),
FileCodeOwnerStatus.addition(
path1,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))),
FileCodeOwnerStatus.addition(
path2,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))))
.inOrder();
assertThat(codeOwnerStatus).hasAccounts(user);
codeOwnerStatus =
changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withStart(1).get();
assertThat(codeOwnerStatus)
.hasPatchSetNumberThat()
.isEqualTo(r.getChange().currentPatchSet().id().get());
assertThat(codeOwnerStatus)
.hasFileCodeOwnerStatusesThat()
.comparingElementsUsing(isFileCodeOwnerStatus())
.containsExactly(
FileCodeOwnerStatus.addition(path3, CodeOwnerStatus.INSUFFICIENT_REVIEWERS),
FileCodeOwnerStatus.addition(
path1,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))),
FileCodeOwnerStatus.addition(
path2,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))))
.inOrder();
assertThat(codeOwnerStatus).hasAccounts(user);
codeOwnerStatus =
changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withStart(2).get();
assertThat(codeOwnerStatus)
.hasPatchSetNumberThat()
.isEqualTo(r.getChange().currentPatchSet().id().get());
assertThat(codeOwnerStatus)
.hasFileCodeOwnerStatusesThat()
.comparingElementsUsing(isFileCodeOwnerStatus())
.containsExactly(
FileCodeOwnerStatus.addition(
path1,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))),
FileCodeOwnerStatus.addition(
path2,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))))
.inOrder();
assertThat(codeOwnerStatus).hasAccounts(user);
codeOwnerStatus =
changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withStart(3).get();
assertThat(codeOwnerStatus)
.hasPatchSetNumberThat()
.isEqualTo(r.getChange().currentPatchSet().id().get());
assertThat(codeOwnerStatus)
.hasFileCodeOwnerStatusesThat()
.comparingElementsUsing(isFileCodeOwnerStatus())
.containsExactly(
FileCodeOwnerStatus.addition(
path2,
CodeOwnerStatus.PENDING,
String.format(
"reviewer %s is a code owner",
AccountTemplateUtil.getAccountTemplate(user.id()))));
assertThat(codeOwnerStatus).hasAccounts(user);
codeOwnerStatus =
changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withStart(4).get();
assertThat(codeOwnerStatus)
.hasPatchSetNumberThat()
.isEqualTo(r.getChange().currentPatchSet().id().get());
assertThat(codeOwnerStatus).hasFileCodeOwnerStatusesThat().isEmpty();
assertThat(codeOwnerStatus).hasAccountsThat().isNull();
}