Adapt code and tests to latest Gerrit master

Adapt to the different return type of GetRelated API and
leverage the new ProjectOperations for configuring the project
ACLs in AutomaticMergerTest.

Change-Id: I2ee7a5a13a78d1c80ba46acd95d7bab4b8b75c77
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java
index 948a26b..d48ced1 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java
@@ -81,11 +81,9 @@
    * @throws NoSuchProjectException
    * @throws PermissionBackendException
    */
-  public boolean hasDependentReview(String project, int number)
-      throws IOException, NoSuchChangeException, NoSuchProjectException,
-          PermissionBackendException {
+  public boolean hasDependentReview(String project, int number) throws Exception {
     RevisionResource r = getRevisionResource(project, number);
-    RelatedChangesInfo related = getRelated.apply(r);
+    RelatedChangesInfo related = getRelated.apply(r).value();
     log.debug(String.format("Checking for related changes on review %d", number));
 
     String checkedCommitSha1 = r.getPatchSet().commitId().name();
diff --git a/src/test/java/com/criteo/gerrit/plugins/automerge/AutomaticMergerTest.java b/src/test/java/com/criteo/gerrit/plugins/automerge/AutomaticMergerTest.java
index 49713ec..082e6c9 100644
--- a/src/test/java/com/criteo/gerrit/plugins/automerge/AutomaticMergerTest.java
+++ b/src/test/java/com/criteo/gerrit/plugins/automerge/AutomaticMergerTest.java
@@ -15,6 +15,9 @@
 package com.criteo.gerrit.plugins.automerge;
 
 import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow;
+import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel;
+import static com.google.gerrit.common.data.Permission.SUBMIT;
 
 import com.google.gerrit.acceptance.GerritConfig;
 import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
@@ -22,13 +25,13 @@
 import com.google.gerrit.acceptance.PushOneCommit;
 import com.google.gerrit.acceptance.TestAccount;
 import com.google.gerrit.acceptance.TestPlugin;
+import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
 import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
 import com.google.gerrit.extensions.api.changes.ChangeApi;
 import com.google.gerrit.extensions.api.changes.Changes;
 import com.google.gerrit.extensions.api.changes.ReviewInput;
 import com.google.gerrit.extensions.client.ChangeStatus;
 import com.google.gerrit.extensions.common.ChangeInfo;
-import com.google.gerrit.reviewdb.client.AccountGroup;
 import com.google.gerrit.server.account.externalids.ExternalIds;
 import com.google.inject.Inject;
 import org.junit.Before;
@@ -45,6 +48,7 @@
   private TestAccount regularUser;
   @Inject ExternalIds extIds;
   @Inject RequestScopeOperations requestScopeOperations;
+  @Inject private ProjectOperations projectOperations;
 
   @Before
   public void setup() throws Exception {
@@ -53,8 +57,13 @@
     botUser = accountCreator.create("botuser", "botuser@mycompany.com", "Bot User", BOT_USERS);
     regularUser =
         accountCreator.create("developer", "developer@mycompany.com", "Developer", DEVELOPERS);
-    grant(project, "refs/*", "submit", false, groupUUID(BOT_USERS));
-    grantLabel("Code-Review", -2, 2, project, "refs/*", groupUUID(DEVELOPERS), false);
+
+    projectOperations
+        .project(project)
+        .forUpdate()
+        .add(allow(SUBMIT).ref("refs/*").group(groupUuid(BOT_USERS)))
+        .add(allowLabel("Code-Review").ref("refs/*").group(groupUuid(DEVELOPERS)).range(-2, 2))
+        .update();
   }
 
   @Test
@@ -88,10 +97,6 @@
     assertThat(changeInfo.submitter.email).isEqualTo(botUser.email());
   }
 
-  private AccountGroup.UUID groupUUID(String name) {
-    return groupCache.get(AccountGroup.nameKey(name)).get().getGroupUUID();
-  }
-
   private Changes changesApi() {
     return gApi.changes();
   }