in javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java [788:934]
public void getWithDefaultAndGlobalCodeOwnersAndLimit() throws Exception {
TestAccount globalOwner1 =
accountCreator.create(
"global_owner_1", "global.owner1@example.com", "Global Owner 1", null);
TestAccount globalOwner2 =
accountCreator.create(
"global_owner_2", "global.owner2@example.com", "Global Owner 2", null);
TestAccount user2 = accountCreator.user2();
TestAccount defaultCodeOwner1 =
accountCreator.create("user3", "user3@example.com", "User3", null);
TestAccount defaultCodeOwner2 =
accountCreator.create("user4", "user4@example.com", "User4", null);
// Create default code owner config file in refs/meta/config.
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch(RefNames.REFS_CONFIG)
.folderPath("/")
.addCodeOwnerEmail(defaultCodeOwner1.email())
.addCodeOwnerEmail(defaultCodeOwner2.email())
.create();
// create some code owner configs
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch("master")
.folderPath("/")
.addCodeOwnerEmail(admin.email())
.create();
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch("master")
.folderPath("/foo/bar/")
.addCodeOwnerEmail(user.email())
.addCodeOwnerEmail(user2.email())
.create();
// get code owners with different limits
CodeOwnersInfo codeOwnersInfo =
queryCodeOwners(getCodeOwnersApi().query().withLimit(1), "/foo/bar/baz.md");
assertThat(codeOwnersInfo).hasCodeOwnersThat().hasSize(1);
// the first 2 code owners have the same scoring, so their order is random and we don't know
// which of them we get when the limit is 1
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(0)
.hasAccountIdThat()
.isAnyOf(user.id(), user2.id());
codeOwnersInfo = queryCodeOwners(getCodeOwnersApi().query().withLimit(2), "/foo/bar/baz.md");
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.comparingElementsUsing(hasAccountId())
.containsExactly(user.id(), user2.id());
codeOwnersInfo = getCodeOwnersApi().query().withLimit(3).get("/foo/bar/baz.md");
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.comparingElementsUsing(hasAccountId())
.containsExactly(admin.id(), user.id(), user2.id());
codeOwnersInfo = getCodeOwnersApi().query().withLimit(4).get("/foo/bar/baz.md");
assertThat(codeOwnersInfo).hasCodeOwnersThat().hasSize(4);
// the order of the first 2 code owners is random
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(0)
.hasAccountIdThat()
.isAnyOf(user.id(), user2.id());
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(1)
.hasAccountIdThat()
.isAnyOf(user.id(), user2.id());
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(2)
.hasAccountIdThat()
.isEqualTo(admin.id());
// the order of the default code owners is random
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(3)
.hasAccountIdThat()
.isAnyOf(defaultCodeOwner1.id(), defaultCodeOwner2.id());
codeOwnersInfo = getCodeOwnersApi().query().withLimit(5).get("/foo/bar/baz.md");
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.comparingElementsUsing(hasAccountId())
.containsExactly(
admin.id(), user.id(), user2.id(), defaultCodeOwner1.id(), defaultCodeOwner2.id());
codeOwnersInfo = getCodeOwnersApi().query().withLimit(6).get("/foo/bar/baz.md");
assertThat(codeOwnersInfo).hasCodeOwnersThat().hasSize(6);
// the order of the first 2 code owners is random
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(0)
.hasAccountIdThat()
.isAnyOf(user.id(), user2.id());
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(1)
.hasAccountIdThat()
.isAnyOf(user.id(), user2.id());
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(2)
.hasAccountIdThat()
.isEqualTo(admin.id());
// the order of the default code owners is random
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(3)
.hasAccountIdThat()
.isAnyOf(defaultCodeOwner1.id(), defaultCodeOwner2.id());
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(4)
.hasAccountIdThat()
.isAnyOf(defaultCodeOwner1.id(), defaultCodeOwner2.id());
// the order of the global code owners is random
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.element(5)
.hasAccountIdThat()
.isAnyOf(globalOwner1.id(), globalOwner2.id());
codeOwnersInfo = getCodeOwnersApi().query().withLimit(7).get("/foo/bar/baz.md");
assertThat(codeOwnersInfo)
.hasCodeOwnersThat()
.comparingElementsUsing(hasAccountId())
.containsExactly(
admin.id(),
user.id(),
user2.id(),
defaultCodeOwner1.id(),
defaultCodeOwner2.id(),
globalOwner1.id(),
globalOwner2.id());
}