SetReviewersIT: Clean up and simplify
- Replace JUnit assertions with Truth assertions, i.e. instead of: assertTrue(x.contains(y)); assertTrue(x.isEmpty()); Use: assertThat(x).contains(y); assertThat(x).isEmpty(); - Annotate the class as @NoHttpd. - Move creation of the test change into an @Before annotated method. - Move add/remove reviewer operation and assertion of results into a utility method. - Remove the "removeReviewer" test and combine removal of reviewer into the byChangeId and byCommitHash methods. Now, the tests confirm that both addition and removal of reviewer is possible by both changeId and commit hash. Change-Id: I9e5b82efe7bb685f2fefb6e5b90e3f9a96af8230
This commit is contained in:
parent
3bcf04eea2
commit
0fedcea0d5
@ -14,57 +14,61 @@
|
||||
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.UseSsh;
|
||||
import com.google.gerrit.reviewdb.client.Account.Id;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@UseSsh
|
||||
@NoHttpd
|
||||
public class SetReviewersIT extends AbstractDaemonTest {
|
||||
PushOneCommit.Result change;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
change = createChange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addByCommitHash() throws Exception {
|
||||
PushOneCommit.Result change = createChange();
|
||||
public void byCommitHash() throws Exception {
|
||||
String id = change.getCommit().getId().toString().split("\\s+")[1];
|
||||
addReviewer(id);
|
||||
removeReviewer(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byChangeID() throws Exception {
|
||||
addReviewer(change.getChangeId());
|
||||
removeReviewer(change.getChangeId());
|
||||
}
|
||||
|
||||
private void setReviewer(boolean add, String id) throws Exception {
|
||||
adminSshSession.exec(
|
||||
"gerrit set-reviewers -a "
|
||||
+ user.email
|
||||
+ " "
|
||||
+ change.getCommit().getId().toString().split("\\s+")[1]);
|
||||
String.format("gerrit set-reviewers -%s %s %s", add ? "a" : "r", user.email, id));
|
||||
assert_()
|
||||
.withFailureMessage(adminSshSession.getError())
|
||||
.that(adminSshSession.hasError())
|
||||
.isFalse();
|
||||
assertTrue(change.getChange().getReviewers().all().contains(user.id));
|
||||
ImmutableSet<Id> reviewers = change.getChange().getReviewers().all();
|
||||
if (add) {
|
||||
assertThat(reviewers).contains(user.id);
|
||||
} else {
|
||||
assertThat(reviewers).doesNotContain(user.id);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addByChangeID() throws Exception {
|
||||
PushOneCommit.Result change = createChange();
|
||||
adminSshSession.exec("gerrit set-reviewers -a " + user.email + " " + change.getChangeId());
|
||||
assert_()
|
||||
.withFailureMessage(adminSshSession.getError())
|
||||
.that(adminSshSession.hasError())
|
||||
.isFalse();
|
||||
assertTrue(change.getChange().getReviewers().all().contains(user.id));
|
||||
private void addReviewer(String id) throws Exception {
|
||||
setReviewer(true, id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeReviewer() throws Exception {
|
||||
PushOneCommit.Result change = createChange();
|
||||
adminSshSession.exec("gerrit set-reviewers -a " + user.email + " " + change.getChangeId());
|
||||
assert_()
|
||||
.withFailureMessage(adminSshSession.getError())
|
||||
.that(adminSshSession.hasError())
|
||||
.isFalse();
|
||||
assertTrue(change.getChange().getReviewers().all().contains(user.id));
|
||||
adminSshSession.exec("gerrit set-reviewers -r " + user.email + " " + change.getChangeId());
|
||||
assert_()
|
||||
.withFailureMessage(adminSshSession.getError())
|
||||
.that(adminSshSession.hasError())
|
||||
.isFalse();
|
||||
assertTrue(change.getChange().getReviewers().all().asList().isEmpty());
|
||||
private void removeReviewer(String id) throws Exception {
|
||||
setReviewer(false, id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user