Replace GerritBaseTests#sanitizedMethodName with a TestRule

Use delegation to implement a new TestRule that wraps JUnit's TestName.
Avoids the need for inheriting from a base class just to use this
method.

Change-Id: Ia3d8487f9b3d65f62d8d1c815e4d009794af2779
This commit is contained in:
Dave Borowitz
2019-05-02 08:19:48 -07:00
parent 8add66e899
commit bbe05196fd
17 changed files with 121 additions and 33 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
@ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
}
}
@Rule public final GerritTestName testName = new GerritTestName();
@Override
protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
protected Injector createInjector() {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
}