in javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java [1452:1538]
public void checkCodeOwnerWithAnnotations() throws Exception {
skipTestIfAnnotationsNotSupportedByCodeOwnersBackend();
TestAccount codeOwner =
accountCreator.create(
"codeOwner", "codeOwner@example.com", "Code Owner", /* displayName= */ null);
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch("master")
.folderPath("/")
.addCodeOwnerSet(
CodeOwnerSet.builder()
.addCodeOwnerEmail(codeOwner.email())
.addAnnotation(
codeOwner.email(), CodeOwnerAnnotations.LAST_RESORT_SUGGESTION_ANNOTATION)
.build())
.create();
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch("master")
.folderPath("/foo/")
.addCodeOwnerSet(
CodeOwnerSet.builder()
.addCodeOwnerEmail(CodeOwnerResolver.ALL_USERS_WILDCARD)
.addAnnotation(
CodeOwnerResolver.ALL_USERS_WILDCARD, CodeOwnerAnnotation.create("ANNOTATION"))
.build())
.create();
codeOwnerConfigOperations
.newCodeOwnerConfig()
.project(project)
.branch("master")
.folderPath("/foo/bar/")
.addCodeOwnerSet(
CodeOwnerSet.builder()
.addCodeOwnerEmail(codeOwner.email())
.addAnnotation(
codeOwner.email(), CodeOwnerAnnotations.LAST_RESORT_SUGGESTION_ANNOTATION)
.addAnnotation(codeOwner.email(), CodeOwnerAnnotation.create("OTHER_ANNOTATION"))
.build())
.create();
String path = "/foo/bar/baz.md";
CodeOwnerCheckInfo checkCodeOwnerInfo = checkCodeOwner(path, codeOwner.email());
assertThat(checkCodeOwnerInfo).isCodeOwner();
assertThat(checkCodeOwnerInfo)
.hasAnnotationsThat()
.containsExactly(CodeOwnerAnnotations.LAST_RESORT_SUGGESTION_ANNOTATION.key())
.inOrder();
assertThat(checkCodeOwnerInfo)
.hasDebugLogsThatContainAllOf(
String.format(
"found email %s as a code owner in %s",
codeOwner.email(), getCodeOwnerConfigFilePath("/foo/bar/")),
String.format(
"email %s is annotated with %s",
codeOwner.email(),
ImmutableSet.of(
CodeOwnerAnnotations.LAST_RESORT_SUGGESTION_ANNOTATION.key(),
"OTHER_ANNOTATION")),
String.format(
"found the all users wildcard ('%s') as a code owner in %s which makes %s a code"
+ " owner",
CodeOwnerResolver.ALL_USERS_WILDCARD,
getCodeOwnerConfigFilePath("/foo/"),
codeOwner.email()),
String.format(
"found annotations for the all users wildcard ('%s') which apply to %s: %s",
CodeOwnerResolver.ALL_USERS_WILDCARD,
codeOwner.email(),
ImmutableSet.of("ANNOTATION")),
String.format(
"found email %s as a code owner in %s",
codeOwner.email(), getCodeOwnerConfigFilePath("/")),
String.format(
"email %s is annotated with %s",
codeOwner.email(),
ImmutableSet.of(CodeOwnerAnnotations.LAST_RESORT_SUGGESTION_ANNOTATION.key())),
String.format(
"dropping unsupported annotations for %s: %s",
codeOwner.email(), ImmutableSet.of("ANNOTATION", "OTHER_ANNOTATION")));
}