Remove Parameterized runner from JUnit tests
Not every JUnit runner supports org.junit.runners.Parameterized, Buck's native java_test() rule doesn't support it and some IDEs have had trouble with it in the past. Use specific test methods that delegate to the implementation. Change-Id: I4df9c4beabd62e6a034216ede80d29913e112562
This commit is contained in:
@@ -18,7 +18,6 @@ import static com.google.gerrit.acceptance.git.GitUtil.cloneProject;
|
|||||||
import static com.google.gerrit.acceptance.git.GitUtil.createProject;
|
import static com.google.gerrit.acceptance.git.GitUtil.createProject;
|
||||||
import static com.google.gerrit.acceptance.git.GitUtil.initSsh;
|
import static com.google.gerrit.acceptance.git.GitUtil.initSsh;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.AccountCreator;
|
import com.google.gerrit.acceptance.AccountCreator;
|
||||||
import com.google.gerrit.acceptance.SshSession;
|
import com.google.gerrit.acceptance.SshSession;
|
||||||
@@ -37,29 +36,14 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class PushForReviewIT extends AbstractDaemonTest {
|
public class PushForReviewIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
private enum Protocol {
|
private enum Protocol {
|
||||||
SSH, HTTP
|
SSH, HTTP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters(name="{0}")
|
|
||||||
public static List<Object[]> getParam() {
|
|
||||||
List<Object[]> params = Lists.newArrayList();
|
|
||||||
for(Protocol p : Protocol.values()) {
|
|
||||||
params.add(new Object[] {p});
|
|
||||||
}
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AccountCreator accounts;
|
private AccountCreator accounts;
|
||||||
|
|
||||||
@@ -70,11 +54,7 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
private Project.NameKey project;
|
private Project.NameKey project;
|
||||||
private Git git;
|
private Git git;
|
||||||
private ReviewDb db;
|
private ReviewDb db;
|
||||||
private Protocol protocol;
|
private String sshUrl;
|
||||||
|
|
||||||
public PushForReviewIT(Protocol p) {
|
|
||||||
this.protocol = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -86,21 +66,25 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
initSsh(admin);
|
initSsh(admin);
|
||||||
SshSession sshSession = new SshSession(admin);
|
SshSession sshSession = new SshSession(admin);
|
||||||
createProject(sshSession, project.get());
|
createProject(sshSession, project.get());
|
||||||
|
sshUrl = sshSession.getUrl();
|
||||||
|
sshSession.close();
|
||||||
|
|
||||||
|
db = reviewDbProvider.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectProtocol(Protocol p) throws GitAPIException, IOException {
|
||||||
String url;
|
String url;
|
||||||
switch (protocol) {
|
switch (p) {
|
||||||
case SSH:
|
case SSH:
|
||||||
url = sshSession.getUrl();
|
url = sshUrl;
|
||||||
break;
|
break;
|
||||||
case HTTP:
|
case HTTP:
|
||||||
url = admin.getHttpUrl();
|
url = admin.getHttpUrl();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("unexpected protocol: " + protocol);
|
throw new IllegalArgumentException("unexpected protocol: " + p);
|
||||||
}
|
}
|
||||||
git = cloneProject(url + "/" + project.get());
|
git = cloneProject(url + "/" + project.get());
|
||||||
sshSession.close();
|
|
||||||
|
|
||||||
db = reviewDbProvider.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -109,16 +93,40 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushForMaster() throws GitAPIException, OrmException,
|
public void testPushForMaster_HTTP() throws GitAPIException, OrmException,
|
||||||
IOException {
|
IOException {
|
||||||
|
testPushForMaster(Protocol.HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushForMaster_SSH() throws GitAPIException, OrmException,
|
||||||
|
IOException {
|
||||||
|
testPushForMaster(Protocol.SSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPushForMaster(Protocol p) throws GitAPIException,
|
||||||
|
OrmException, IOException {
|
||||||
|
selectProtocol(p);
|
||||||
PushOneCommit.Result r = pushTo("refs/for/master");
|
PushOneCommit.Result r = pushTo("refs/for/master");
|
||||||
r.assertOkStatus();
|
r.assertOkStatus();
|
||||||
r.assertChange(Change.Status.NEW, null);
|
r.assertChange(Change.Status.NEW, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushForMasterWithTopic() throws GitAPIException,
|
public void testPushForMasterWithTopic_HTTP()
|
||||||
|
throws GitAPIException, OrmException, IOException {
|
||||||
|
testPushForMasterWithTopic(Protocol.HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushForMasterWithTopic_SSH()
|
||||||
|
throws GitAPIException, OrmException, IOException {
|
||||||
|
testPushForMasterWithTopic(Protocol.SSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPushForMasterWithTopic(Protocol p) throws GitAPIException,
|
||||||
OrmException, IOException {
|
OrmException, IOException {
|
||||||
|
selectProtocol(p);
|
||||||
// specify topic in ref
|
// specify topic in ref
|
||||||
String topic = "my/topic";
|
String topic = "my/topic";
|
||||||
PushOneCommit.Result r = pushTo("refs/for/master/" + topic);
|
PushOneCommit.Result r = pushTo("refs/for/master/" + topic);
|
||||||
@@ -132,8 +140,20 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushForMasterWithCc() throws GitAPIException, OrmException,
|
public void testPushForMasterWithCc_HTTP() throws GitAPIException,
|
||||||
IOException, JSchException {
|
OrmException, IOException, JSchException {
|
||||||
|
testPushForMasterWithCc(Protocol.HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushForMasterWithCc_SSH() throws GitAPIException,
|
||||||
|
OrmException, IOException, JSchException {
|
||||||
|
testPushForMasterWithCc(Protocol.SSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPushForMasterWithCc(Protocol p) throws GitAPIException,
|
||||||
|
OrmException, IOException, JSchException {
|
||||||
|
selectProtocol(p);
|
||||||
// cc one user
|
// cc one user
|
||||||
TestAccount user = accounts.create("user", "user@example.com", "User");
|
TestAccount user = accounts.create("user", "user@example.com", "User");
|
||||||
String topic = "my/topic";
|
String topic = "my/topic";
|
||||||
@@ -157,8 +177,20 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushForMasterWithReviewer() throws GitAPIException,
|
public void testPushForMasterWithReviewer_HTTP() throws GitAPIException,
|
||||||
OrmException, IOException, JSchException {
|
OrmException, IOException, JSchException {
|
||||||
|
testPushForMasterWithReviewer(Protocol.HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushForMasterWithReviewer_SSH() throws GitAPIException,
|
||||||
|
OrmException, IOException, JSchException {
|
||||||
|
testPushForMasterWithReviewer(Protocol.SSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPushForMasterWithReviewer(Protocol p)
|
||||||
|
throws GitAPIException, OrmException, IOException, JSchException {
|
||||||
|
selectProtocol(p);
|
||||||
// add one reviewer
|
// add one reviewer
|
||||||
TestAccount user = accounts.create("user", "user@example.com", "User");
|
TestAccount user = accounts.create("user", "user@example.com", "User");
|
||||||
String topic = "my/topic";
|
String topic = "my/topic";
|
||||||
@@ -183,8 +215,20 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushForMasterAsDraft() throws GitAPIException, OrmException,
|
public void testPushForMasterAsDraft_HTTP() throws GitAPIException,
|
||||||
IOException {
|
OrmException, IOException {
|
||||||
|
testPushForMasterAsDraft(Protocol.HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushForMasterAsDraft_SSH() throws GitAPIException,
|
||||||
|
OrmException, IOException {
|
||||||
|
testPushForMasterAsDraft(Protocol.SSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPushForMasterAsDraft(Protocol p) throws GitAPIException,
|
||||||
|
OrmException, IOException {
|
||||||
|
selectProtocol(p);
|
||||||
// create draft by pushing to 'refs/drafts/'
|
// create draft by pushing to 'refs/drafts/'
|
||||||
PushOneCommit.Result r = pushTo("refs/drafts/master");
|
PushOneCommit.Result r = pushTo("refs/drafts/master");
|
||||||
r.assertOkStatus();
|
r.assertOkStatus();
|
||||||
@@ -197,8 +241,20 @@ public class PushForReviewIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushForNonExistingBranch() throws GitAPIException,
|
public void testPushForNonExistingBranch_HTTP() throws GitAPIException,
|
||||||
OrmException, IOException {
|
OrmException, IOException {
|
||||||
|
testPushForNonExistingBranch(Protocol.HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushForNonExistingBranch_SSH() throws GitAPIException,
|
||||||
|
OrmException, IOException {
|
||||||
|
testPushForNonExistingBranch(Protocol.SSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPushForNonExistingBranch(Protocol p) throws GitAPIException,
|
||||||
|
OrmException, IOException {
|
||||||
|
selectProtocol(p);
|
||||||
String branchName = "non-existing";
|
String branchName = "non-existing";
|
||||||
PushOneCommit.Result r = pushTo("refs/for/" + branchName);
|
PushOneCommit.Result r = pushTo("refs/for/" + branchName);
|
||||||
r.assertErrorStatus("branch " + branchName + " not found");
|
r.assertErrorStatus("branch " + branchName + " not found");
|
||||||
|
Reference in New Issue
Block a user