Make most small tests inherit from GerritBaseTests
One of the main purposes of GerritBaseTests is a place to park the
KeyUtil#setEncoderImpl call, which avoids NPEs when calling any gwtorm
Key#toString method. Many tests pass today without this base class for
one of a few reasons:
* They never call Key#toString, or perhaps only call it lazily on test
failures.
* They transitively load some other class which has setEncoderImpl in
its static block, such as Database.
* They are run with `bazel test` in the same JVM/classloader as another
test class which does inherit GerritBaseTests or otherwise indirectly
calls setEncoderImpl. (If any tests exist in this category, then they
already fail if run singly in an IDE or with a restricted
--test_filter.)
In order to avoid having to reason about whether a particular test does
or does not depend on setEncoderImpl, just use GerritBaseTests
consistently. This will prevent spurious test failures when we start
removing classes like Database as we cut out ReviewDb.
This change modifies all classes named *Test.java which were not
previously inheriting from any base class. Remaining tests will be fixed
in followups.
Change-Id: I32f5456d2ebc5e545cc89ad65f74139bd3506aaa
diff --git a/javatests/com/google/gerrit/elasticsearch/BUILD b/javatests/com/google/gerrit/elasticsearch/BUILD
index cc849eb..51d45f2 100644
--- a/javatests/com/google/gerrit/elasticsearch/BUILD
+++ b/javatests/com/google/gerrit/elasticsearch/BUILD
@@ -86,6 +86,7 @@
tags = ["elastic"],
deps = [
"//java/com/google/gerrit/elasticsearch",
+ "//java/com/google/gerrit/testing:gerrit-test-util",
"//lib:guava",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",
diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticConfigurationTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticConfigurationTest.java
index 559b8c7..86b564b 100644
--- a/javatests/com/google/gerrit/elasticsearch/ElasticConfigurationTest.java
+++ b/javatests/com/google/gerrit/elasticsearch/ElasticConfigurationTest.java
@@ -27,6 +27,7 @@
import static java.util.stream.Collectors.toList;
import com.google.common.collect.ImmutableList;
+import com.google.gerrit.testing.GerritBaseTests;
import com.google.inject.ProvisionException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@@ -35,7 +36,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
-public class ElasticConfigurationTest {
+public class ElasticConfigurationTest extends GerritBaseTests {
@Rule public ExpectedException exception = ExpectedException.none();
@Test
diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticVersionTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticVersionTest.java
index b598a0a..56584b1 100644
--- a/javatests/com/google/gerrit/elasticsearch/ElasticVersionTest.java
+++ b/javatests/com/google/gerrit/elasticsearch/ElasticVersionTest.java
@@ -16,11 +16,12 @@
import static com.google.common.truth.Truth.assertThat;
+import com.google.gerrit.testing.GerritBaseTests;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-public class ElasticVersionTest {
+public class ElasticVersionTest extends GerritBaseTests {
@Rule public ExpectedException exception = ExpectedException.none();
@Test