Improve readability of getAllUsersAsCodeOwners_withViewAllAccounts

Also verify that no accounts are returned if VIEW_ALL_ACCOUNTS is not
assigned. This only works if the call is done by a non-admin user since
admin users have the VIEW_ALL_ACCOUNTS capabilities implicitly assigned.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ic95f3a75db504ed6d2d6acd5c683013827a43372
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
index fb51e53..d7d3da3 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
@@ -1100,12 +1100,6 @@
   @Test
   @GerritConfig(name = "accounts.visibility", value = "NONE")
   public void getAllUsersAsCodeOwners_withViewAllAccounts() throws Exception {
-    // Allow all users to view all accounts.
-    projectOperations
-        .allProjectsForUpdate()
-        .add(allowCapability(GlobalCapability.VIEW_ALL_ACCOUNTS).group(REGISTERED_USERS))
-        .update();
-
     TestAccount user2 = accountCreator.user2();
 
     // Add a code owner config that makes all users code owners.
@@ -1117,7 +1111,22 @@
         .addCodeOwnerEmail("*")
         .create();
 
+    requestScopeOperations.setApiUser(user.id());
+
+    // Since accounts.visibility = NONE, no account is visible and hence the list of code owners is
+    // empty.
     CodeOwnersInfo codeOwnersInfo = queryCodeOwners("/foo/bar/baz.md");
+    assertThat(codeOwnersInfo).hasCodeOwnersThat().isEmpty();
+    assertThat(codeOwnersInfo).hasOwnedByAllUsersThat().isTrue();
+
+    // Allow all users to view all accounts.
+    projectOperations
+        .allProjectsForUpdate()
+        .add(allowCapability(GlobalCapability.VIEW_ALL_ACCOUNTS).group(REGISTERED_USERS))
+        .update();
+
+    // If VIEW_ALL_ACCOUNTS is assigned, all accounts are visible now.
+    codeOwnersInfo = queryCodeOwners("/foo/bar/baz.md");
     assertThat(codeOwnersInfo)
         .hasCodeOwnersThat()
         .comparingElementsUsing(hasAccountId())