PluginsRepositoryTest: Skip test when expected env variables are not set

If either the TEST_SRCDIR or TEST_WORKSPACE environment variables is
not defined, the subsequent call to Paths.get will fail with NPE on
dereferencing the null value returned by System.getenv. This happens
when running the test in Eclipse and is expected because when running
in Eclipse the release.war is not built.

Refactor it so that the values are explicitly checked for nullness
prior to dereferencing, and the test is skipped if they are.

Also refactor the subsequent check for existence of the release.war to
an assumption that causes the test to skip, rather than failing.

Bug: Issue 11699
Change-Id: Ibf9463cc237bd0f613a09a093b5257af92e7efda
diff --git a/src/test/java/com/googlesource/gerrit/plugins/manager/repository/PluginsRepositoryTest.java b/src/test/java/com/googlesource/gerrit/plugins/manager/repository/PluginsRepositoryTest.java
index 31f39f8..d01d287 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/manager/repository/PluginsRepositoryTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/manager/repository/PluginsRepositoryTest.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.manager.repository;
 
 import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.TruthJUnit.assume;
 import static java.util.stream.Collectors.toList;
 
 import com.google.common.collect.ImmutableList;
@@ -49,10 +50,8 @@
     PluginsRepository pluginRepo = new CorePluginsRepository(site, new CorePluginsDescriptions());
 
     Path pathToReleaseWar =
-        Paths.get(System.getenv("TEST_SRCDIR"), System.getenv("TEST_WORKSPACE"), "release.war");
-    if (!pathToReleaseWar.toFile().exists()) {
-      throw new IllegalStateException("Cannot find release.war");
-    }
+        Paths.get(getenv("TEST_SRCDIR"), getenv("TEST_WORKSPACE"), "release.war");
+    assume().that(pathToReleaseWar.toFile().exists()).isTrue();
     Files.createDirectories(site.bin_dir);
     Files.createSymbolicLink(site.gerrit_war, pathToReleaseWar);
 
@@ -62,6 +61,12 @@
         .inOrder();
   }
 
+  private static String getenv(String name) {
+    String value = System.getenv(name);
+    assume().that(value).isNotNull();
+    return value;
+  }
+
   private static Path random() throws IOException {
     Path tmp = Files.createTempFile("gerrit_", "_site");
     Files.deleteIfExists(tmp);