Add helper method to skip tests

This makes the tests a bit more readable and removes some duplicate
code.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I6896af1846906c4b25543cc49cec3981cf61c6a0
diff --git a/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersIT.java b/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersIT.java
index 0b50f6e..26578fc 100644
--- a/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersIT.java
+++ b/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersIT.java
@@ -15,6 +15,7 @@
 package com.google.gerrit.plugins.codeowners.acceptance;
 
 import static com.google.common.collect.ImmutableMap.toImmutableMap;
+import static com.google.common.truth.TruthJUnit.assume;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.gerrit.plugins.codeowners.acceptance.testsuite.CodeOwnerConfigOperations;
@@ -24,6 +25,7 @@
 import com.google.gerrit.plugins.codeowners.api.impl.ProjectCodeOwnersFactory;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerBackendId;
 import com.google.gerrit.plugins.codeowners.backend.config.BackendConfig;
+import com.google.gerrit.plugins.codeowners.backend.proto.ProtoBackend;
 import com.google.gerrit.testing.ConfigSuite;
 import java.util.Arrays;
 import org.eclipse.jgit.lib.Config;
@@ -76,6 +78,8 @@
   protected ChangeCodeOwnersFactory changeCodeOwnersApiFactory;
   protected ProjectCodeOwnersFactory projectCodeOwnersApiFactory;
 
+  private BackendConfig backendConfig;
+
   @Before
   public void baseSetup() throws Exception {
     codeOwnerConfigOperations =
@@ -85,5 +89,15 @@
     changeCodeOwnersApiFactory = plugin.getSysInjector().getInstance(ChangeCodeOwnersFactory.class);
     projectCodeOwnersApiFactory =
         plugin.getSysInjector().getInstance(ProjectCodeOwnersFactory.class);
+    backendConfig = plugin.getSysInjector().getInstance(BackendConfig.class);
+  }
+
+  protected void skipTestIfImportsNotSupportedByCodeOwnersBackend() {
+    // the proto backend doesn't support imports
+    assumeThatCodeOwnersBackendIsNotProtoBackend();
+  }
+
+  protected void assumeThatCodeOwnersBackendIsNotProtoBackend() {
+    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
   }
 }
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java
index 758d0ef..a2e37ef 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java
@@ -15,7 +15,6 @@
 package com.google.gerrit.plugins.codeowners.acceptance.api;
 
 import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.TruthJUnit.assume;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block;
 import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
 import static com.google.gerrit.testing.GerritJUnit.assertThrows;
@@ -196,8 +195,7 @@
 
   private void testIssuesInCodeOwnerConfigFile(ConsistencyProblemInfo.Status expectedStatus)
       throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // Create some code owner config files with issues.
     CodeOwnerConfig.Key keyOfInvalidConfig1 =
@@ -393,8 +391,7 @@
 
   @Test
   public void validateExactFile() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // Create some code owner config files with issues.
     CodeOwnerConfig.Key keyOfInvalidConfig1 =
@@ -466,8 +463,7 @@
 
   @Test
   public void validateFilesMatchingGlob() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // Create some code owner config files with issues.
     codeOwnerConfigOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
index 282594b..8166970 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
@@ -15,7 +15,6 @@
 package com.google.gerrit.plugins.codeowners.acceptance.api;
 
 import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.TruthJUnit.assume;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability;
 import static com.google.gerrit.plugins.codeowners.testing.CodeOwnerCheckInfoSubject.assertThat;
 import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
@@ -612,8 +611,7 @@
 
   @Test
   public void debugLogsContainUnresolvedImports() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfigReference unresolvableCodeOwnerConfigReference =
         CodeOwnerConfigReference.create(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
index e65efbd..12b3360 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
@@ -15,7 +15,6 @@
 package com.google.gerrit.plugins.codeowners.acceptance.api;
 
 import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.TruthJUnit.assume;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block;
 import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
@@ -152,8 +151,7 @@
 
   @Test
   public void canUploadConfigWithoutIssues_withImport() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey = createCodeOwnerConfigKey("/");
 
@@ -198,8 +196,7 @@
 
   @Test
   public void canUploadConfigWithoutIssues_withImportFromOtherProject() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey = createCodeOwnerConfigKey("/");
 
@@ -243,8 +240,7 @@
 
   @Test
   public void canUploadConfigWithoutIssues_withImportFromOtherProjectAndBranch() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey = createCodeOwnerConfigKey("/");
 
@@ -292,8 +288,7 @@
   public void
       canUploadConfigWithImportOfConfigThatIsAddedInSameCommit_importModeGlobalCodeOwnersOnly()
           throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey = createCodeOwnerConfigKey("/");
     CodeOwnerConfig.Key keyOfImportedCodeOwnerConfig = createCodeOwnerConfigKey("/foo/");
@@ -332,8 +327,7 @@
   @Test
   public void canUploadConfigWithImportOfConfigThatIsAddedInSameCommit_importModeAll()
       throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey = createCodeOwnerConfigKey("/");
     CodeOwnerConfig.Key keyOfImportedCodeOwnerConfig = createCodeOwnerConfigKey("/foo/");
@@ -1040,8 +1034,7 @@
 
   private void testUploadConfigWithImportFromNonExistingProject(
       CodeOwnerConfigImportType importType) throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // create a code owner config that imports a code owner config from a non-existing project
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
@@ -1087,8 +1080,7 @@
 
   private void testUploadConfigWithImportFromNonVisibleProject(CodeOwnerConfigImportType importType)
       throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // create a non-visible project with a code owner config file that we try to import
     Project.NameKey nonVisibleProject =
@@ -1150,8 +1142,7 @@
 
   private void testUploadConfigWithImportFromHiddenProject(CodeOwnerConfigImportType importType)
       throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // create a hidden project with a code owner config file
     Project.NameKey hiddenProject =
@@ -1210,8 +1201,7 @@
 
   private void testUploadConfigWithImportFromNonExistingBranch(CodeOwnerConfigImportType importType)
       throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // create a code owner config that imports a code owner config from a non-existing branch
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
@@ -1258,8 +1248,7 @@
 
   private void testUploadConfigWithImportFromNonVisibleBranch(CodeOwnerConfigImportType importType)
       throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
 
@@ -1323,8 +1312,7 @@
 
   private void testUploadConfigWithImportOfNonCodeOwnerConfigFile(
       CodeOwnerConfigImportType importType) throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // create a code owner config that imports a non code owner config file
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
@@ -1368,8 +1356,7 @@
 
   private void testUploadConfigWithImportOfNonExistingCodeOwnerConfig(
       CodeOwnerConfigImportType importType) throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     // create a code owner config that imports a non-existing code owner config
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
@@ -1421,8 +1408,7 @@
 
   private void testUploadConfigWithImportOfNonParseableCodeOwnerConfig(
       CodeOwnerConfigImportType importType) throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key keyOfImportedCodeOwnerConfig =
         CodeOwnerConfig.Key.create(project, "master", "/foo/");
@@ -1629,8 +1615,7 @@
   @Test
   @GerritConfig(name = "plugin.code-owners.rejectNonResolvableImports", value = "false")
   public void canUploadAndSubmitConfigWithUnresolvableImports() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
 
@@ -1685,8 +1670,7 @@
   @GerritConfig(name = "plugin.code-owners.enableValidationOnCommitReceived", value = "false")
   @GerritConfig(name = "plugin.code-owners.enableValidationOnSubmit", value = "false")
   public void rejectConfigOptionsAreIgnoredIfValidationIsDisabled() throws Exception {
-    // imports are not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfImportsNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
 
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
index 40d87a6..463d623 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
@@ -15,7 +15,6 @@
 package com.google.gerrit.plugins.codeowners.acceptance.api;
 
 import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.TruthJUnit.assume;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability;
 import static com.google.gerrit.plugins.codeowners.testing.CodeOwnerConfigSubject.assertThat;
@@ -41,8 +40,6 @@
 import com.google.gerrit.plugins.codeowners.api.RenameEmailResultInfo;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfig;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfigFileUpdateScanner;
-import com.google.gerrit.plugins.codeowners.backend.config.BackendConfig;
-import com.google.gerrit.plugins.codeowners.backend.proto.ProtoBackend;
 import com.google.gerrit.plugins.codeowners.restapi.RenameEmail;
 import com.google.inject.Inject;
 import java.util.Optional;
@@ -62,12 +59,10 @@
   @Inject private ProjectOperations projectOperations;
   @Inject private RequestScopeOperations requestScopeOperations;
 
-  private BackendConfig backendConfig;
   private CodeOwnerConfigFileUpdateScanner codeOwnerConfigFileUpdateScanner;
 
   @Before
   public void setup() throws Exception {
-    backendConfig = plugin.getSysInjector().getInstance(BackendConfig.class);
     codeOwnerConfigFileUpdateScanner =
         plugin.getSysInjector().getInstance(CodeOwnerConfigFileUpdateScanner.class);
   }
@@ -179,8 +174,7 @@
 
   @Test
   public void renameEmail_noUpdateIfEmailIsNotContainedInCodeOwnerConfigs() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
@@ -210,8 +204,7 @@
 
   @Test
   public void renameOwnEmailWithDirectPushPermission() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey1 =
         codeOwnerConfigOperations
@@ -263,8 +256,7 @@
 
   @Test
   public void renameOtherEmailWithDirectPushPermission() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey1 =
         codeOwnerConfigOperations
@@ -323,8 +315,7 @@
 
   @Test
   public void renameOwnEmailAsProjectOwner() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey1 =
         codeOwnerConfigOperations
@@ -368,8 +359,7 @@
 
   @Test
   public void renameOtherEmailAsProjectOwner() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey1 =
         codeOwnerConfigOperations
@@ -413,8 +403,7 @@
 
   @Test
   public void renameEmail_callingUserBecomesCommitAuthor() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
@@ -438,8 +427,7 @@
 
   @Test
   public void renameEmailWithDefaultCommitMessage() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
@@ -463,8 +451,7 @@
 
   @Test
   public void renameEmailWithSpecifiedCommitMessage() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
@@ -489,8 +476,7 @@
 
   @Test
   public void renameEmail_specifiedCommitMessageIsTrimmed() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
@@ -516,8 +502,7 @@
 
   @Test
   public void renameEmail_lineCommentsArePreserved() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey =
         codeOwnerConfigOperations
@@ -580,8 +565,7 @@
 
   @Test
   public void renameEmail_inlineCommentsArePreserved() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey =
         codeOwnerConfigOperations
@@ -642,8 +626,7 @@
 
   @Test
   public void renameEmail_emailInCommentIsReplaced() throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     CodeOwnerConfig.Key codeOwnerConfigKey =
         codeOwnerConfigOperations
@@ -687,8 +670,7 @@
   @Test
   public void renameEmail_emailThatContainsEmailToBeReplacesAsSubstringStaysIntact()
       throws Exception {
-    // renaming email is not supported for the proto backend
-    assume().that(backendConfig.getDefaultBackend()).isNotInstanceOf(ProtoBackend.class);
+    skipTestIfRenameEmailNotSupportedByCodeOwnersBackend();
 
     TestAccount otherUser1 =
         accountCreator.create(
@@ -745,4 +727,9 @@
         .branch(branchName)
         .renameEmailInCodeOwnerConfigFiles(input);
   }
+
+  private void skipTestIfRenameEmailNotSupportedByCodeOwnersBackend() {
+    // the proto backend doesn't support renaming emails
+    assumeThatCodeOwnersBackendIsNotProtoBackend();
+  }
 }