gerrit-server: Move declarations of ExpectedException to base class
Introduce another base class GerritBaseTests that declares an instance of ExpectedException. Update all classes that currently declare their own ExpectedException to derive from the new base class instead. Change-Id: I6c6b53ddecbdb93906757956708480bb018fcbdb
This commit is contained in:
@@ -137,6 +137,7 @@ java_library(
|
|||||||
srcs = PROLOG_TEST_CASE,
|
srcs = PROLOG_TEST_CASE,
|
||||||
deps = [
|
deps = [
|
||||||
':server',
|
':server',
|
||||||
|
':testutil',
|
||||||
'//gerrit-common:server',
|
'//gerrit-common:server',
|
||||||
'//gerrit-extension-api:api',
|
'//gerrit-extension-api:api',
|
||||||
'//lib:guava',
|
'//lib:guava',
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ import com.googlecode.prolog_cafe.lang.SymbolTerm;
|
|||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.io.PushbackReader;
|
import java.io.PushbackReader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@@ -62,9 +60,6 @@ public class GerritCommonTest extends PrologTestCase {
|
|||||||
private ProjectConfig local;
|
private ProjectConfig local;
|
||||||
private Util util;
|
private Util util;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
util = new Util();
|
util = new Util();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assert_;
|
|||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.gerrit.common.TimeUtil;
|
import com.google.gerrit.common.TimeUtil;
|
||||||
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ import java.util.List;
|
|||||||
|
|
||||||
|
|
||||||
/** Base class for any tests written in Prolog. */
|
/** Base class for any tests written in Prolog. */
|
||||||
public abstract class PrologTestCase {
|
public abstract class PrologTestCase extends GerritBaseTests {
|
||||||
private static final SymbolTerm test_1 = SymbolTerm.intern("test", 1);
|
private static final SymbolTerm test_1 = SymbolTerm.intern("test", 1);
|
||||||
|
|
||||||
private String pkg;
|
private String pkg;
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ import org.easymock.IAnswer;
|
|||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.eclipse.jgit.lib.PersonIdent;
|
import org.eclipse.jgit.lib.PersonIdent;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -101,9 +99,6 @@ public class CommentsTest extends GerritServerTests {
|
|||||||
private static final TimeZone TZ =
|
private static final TimeZone TZ =
|
||||||
TimeZone.getTimeZone("America/Los_Angeles");
|
TimeZone.getTimeZone("America/Los_Angeles");
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
private ReviewDb db;
|
private ReviewDb db;
|
||||||
private Project.NameKey project;
|
private Project.NameKey project;
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import com.google.gerrit.server.util.HostPlatform;
|
import com.google.gerrit.server.util.HostPlatform;
|
||||||
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -32,10 +31,7 @@ import java.nio.file.NotDirectoryException;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class SitePathsTest {
|
public class SitePathsTest extends GerritBaseTests {
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_NotExisting() throws IOException {
|
public void testCreate_NotExisting() throws IOException {
|
||||||
final Path root = random();
|
final Path root = random();
|
||||||
|
|||||||
@@ -34,22 +34,18 @@ import com.google.gerrit.server.query.change.ChangeData;
|
|||||||
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||||
import com.google.gerrit.server.query.change.OrSource;
|
import com.google.gerrit.server.query.change.OrSource;
|
||||||
import com.google.gerrit.server.query.change.QueryOptions;
|
import com.google.gerrit.server.query.change.QueryOptions;
|
||||||
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class IndexRewriterTest {
|
public class IndexRewriterTest extends GerritBaseTests {
|
||||||
private static final IndexConfig CONFIG = IndexConfig.createDefault();
|
private static final IndexConfig CONFIG = IndexConfig.createDefault();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
private FakeIndex index;
|
private FakeIndex index;
|
||||||
private IndexCollection indexes;
|
private IndexCollection indexes;
|
||||||
private ChangeQueryBuilder queryBuilder;
|
private ChangeQueryBuilder queryBuilder;
|
||||||
|
|||||||
@@ -16,14 +16,11 @@ package com.google.gerrit.server.mail;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
public class AddressTest {
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
|
public class AddressTest extends GerritBaseTests {
|
||||||
@Test
|
@Test
|
||||||
public void testParse_NameEmail1() {
|
public void testParse_NameEmail1() {
|
||||||
final Address a = Address.parse("A U Thor <author@example.com>");
|
final Address a = Address.parse("A U Thor <author@example.com>");
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
|||||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
import com.google.gerrit.testutil.FakeAccountCache;
|
import com.google.gerrit.testutil.FakeAccountCache;
|
||||||
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||||
import com.google.gerrit.testutil.TestChanges;
|
import com.google.gerrit.testutil.TestChanges;
|
||||||
import com.google.gwtorm.client.KeyUtil;
|
import com.google.gwtorm.client.KeyUtil;
|
||||||
@@ -72,7 +73,7 @@ import java.sql.Timestamp;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public class AbstractChangeNotesTest {
|
public class AbstractChangeNotesTest extends GerritBaseTests {
|
||||||
private static final TimeZone TZ =
|
private static final TimeZone TZ =
|
||||||
TimeZone.getTimeZone("America/Los_Angeles");
|
TimeZone.getTimeZone("America/Los_Angeles");
|
||||||
|
|
||||||
|
|||||||
@@ -27,17 +27,12 @@ import org.eclipse.jgit.revwalk.RevCommit;
|
|||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||||
private TestRepository<InMemoryRepository> testRepo;
|
private TestRepository<InMemoryRepository> testRepo;
|
||||||
private RevWalk walk;
|
private RevWalk walk;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpTestRepo() throws Exception {
|
public void setUpTestRepo() throws Exception {
|
||||||
testRepo = new TestRepository<>(repo);
|
testRepo = new TestRepository<>(repo);
|
||||||
|
|||||||
@@ -14,10 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.query;
|
package com.google.gerrit.server.query;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
public class PredicateTest {
|
public class PredicateTest extends GerritBaseTests {
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,9 +82,7 @@ import org.joda.time.DateTimeUtils.MillisProvider;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -93,9 +91,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Inject protected AccountManager accountManager;
|
@Inject protected AccountManager accountManager;
|
||||||
@Inject protected BatchUpdate.Factory updateFactory;
|
@Inject protected BatchUpdate.Factory updateFactory;
|
||||||
@Inject protected ChangeInserter.Factory changeFactory;
|
@Inject protected ChangeInserter.Factory changeFactory;
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import com.google.gerrit.testutil.GerritBaseTests;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
@@ -34,10 +34,7 @@ import java.net.InetAddress;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class SocketUtilTest {
|
public class SocketUtilTest extends GerritBaseTests {
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsIPv6() throws UnknownHostException {
|
public void testIsIPv6() throws UnknownHostException {
|
||||||
final InetAddress ipv6 = getByName("1:2:3:4:5:6:7:8");
|
final InetAddress ipv6 = getByName("1:2:3:4:5:6:7:8");
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2015 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.testutil;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
|
public class GerritBaseTests {
|
||||||
|
@Rule
|
||||||
|
public ExpectedException exception = ExpectedException.none();
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ import org.junit.runners.model.Statement;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@RunWith(ConfigSuite.class)
|
@RunWith(ConfigSuite.class)
|
||||||
public class GerritServerTests {
|
public class GerritServerTests extends GerritBaseTests {
|
||||||
@ConfigSuite.Parameter
|
@ConfigSuite.Parameter
|
||||||
public Config config;
|
public Config config;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user