public void getStatusWithLimit()

in javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetCodeOwnerStatusIT.java [226:338]


  public void getStatusWithLimit() 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().withLimit(1).get();
    assertThat(codeOwnerStatus)
        .hasPatchSetNumberThat()
        .isEqualTo(r.getChange().currentPatchSet().id().get());
    assertThat(codeOwnerStatus)
        .hasFileCodeOwnerStatusesThat()
        .comparingElementsUsing(isFileCodeOwnerStatus())
        .containsExactly(
            FileCodeOwnerStatus.addition(path4, CodeOwnerStatus.INSUFFICIENT_REVIEWERS));
    assertThat(codeOwnerStatus).hasAccountsThat().isNull();
    assertThat(codeOwnerStatus).hasMoreThat().isTrue();

    codeOwnerStatus =
        changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withLimit(2).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))
        .inOrder();
    assertThat(codeOwnerStatus).hasAccountsThat().isNull();
    assertThat(codeOwnerStatus).hasMoreThat().isTrue();

    codeOwnerStatus =
        changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withLimit(3).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()))))
        .inOrder();
    assertThat(codeOwnerStatus).hasAccounts(user);
    assertThat(codeOwnerStatus).hasMoreThat().isTrue();

    codeOwnerStatus =
        changeCodeOwnersApiFactory.change(changeId).getCodeOwnerStatus().withLimit(4).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);
    assertThat(codeOwnerStatus).hasMoreThat().isNull();
  }