ChangeApi: Add convenience overrides for get with options

Almost all callers just want to list some options explicitly, rather
than reusing an EnumSet. A single method taking EnumSet may have made
sense before Java 8, but now that we have default methods, it is trivial
to add the necessary overrides.

Clean up call sites by using the new override, and statically importing
constants to make things more readable still.

Change-Id: If7cc40a3314c88ef9050fa3c4a9754e425459303
This commit is contained in:
Dave Borowitz
2017-09-11 10:10:35 -04:00
parent fa9a0c3d1e
commit 3b979d9cba
11 changed files with 80 additions and 122 deletions

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.acceptance.GitUtil.initSsh;
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
import static com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS;
import static com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG;
import static com.google.gerrit.reviewdb.client.Patch.MERGE_LIST;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
@@ -30,7 +31,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.jimfs.Jimfs;
import com.google.common.primitives.Chars;
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
@@ -643,11 +643,7 @@ public abstract class AbstractDaemonTest {
private List<Boolean> getPatchSetDraftStatuses(Change.Id id) throws Exception {
Collection<RevisionInfo> revisionInfos =
gApi.changes()
.id(id.get())
.get(EnumSet.of(ListChangesOption.ALL_REVISIONS))
.revisions
.values();
gApi.changes().id(id.get()).get(ALL_REVISIONS).revisions.values();
return revisionInfos.stream().map(revisionInfo -> revisionInfo.draft).collect(toList());
}
@@ -804,9 +800,7 @@ public abstract class AbstractDaemonTest {
}
protected ChangeInfo get(String id, ListChangesOption... options) throws RestApiException {
return gApi.changes()
.id(id)
.get(Sets.newEnumSet(Arrays.asList(options), ListChangesOption.class));
return gApi.changes().id(id).get(options);
}
protected List<ChangeInfo> query(String q) throws RestApiException {

View File

@@ -22,6 +22,20 @@ import static com.google.gerrit.acceptance.GitUtil.pushHead;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
import static com.google.gerrit.acceptance.PushOneCommit.SUBJECT;
import static com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CHANGE_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CHECK;
import static com.google.gerrit.extensions.client.ListChangesOption.COMMIT_FOOTERS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_ACCOUNTS;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import static com.google.gerrit.extensions.client.ListChangesOption.LABELS;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.extensions.client.ListChangesOption.PUSH_CERTIFICATES;
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWED;
import static com.google.gerrit.extensions.client.ListChangesOption.TRACKING_IDS;
import static com.google.gerrit.extensions.client.ReviewerState.CC;
import static com.google.gerrit.extensions.client.ReviewerState.REMOVED;
import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER;
@@ -74,7 +88,6 @@ import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.client.SubmitType;
@@ -130,7 +143,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -704,17 +716,11 @@ public class ChangeIT extends AbstractDaemonTest {
rebase.call(changeId);
// Second change should have 2 patch sets and an approval
ChangeInfo c2 =
gApi.changes()
.id(changeId)
.get(EnumSet.of(ListChangesOption.CURRENT_REVISION, ListChangesOption.DETAILED_LABELS));
ChangeInfo c2 = gApi.changes().id(changeId).get(CURRENT_REVISION, DETAILED_LABELS);
assertThat(c2.revisions.get(c2.currentRevision)._number).isEqualTo(2);
// ...and the committer and description should be correct
ChangeInfo info =
gApi.changes()
.id(changeId)
.get(EnumSet.of(ListChangesOption.CURRENT_REVISION, ListChangesOption.CURRENT_COMMIT));
ChangeInfo info = gApi.changes().id(changeId).get(CURRENT_REVISION, CURRENT_COMMIT);
GitPerson committer = info.revisions.get(info.currentRevision).commit.committer;
assertThat(committer.name).isEqualTo(admin.fullName);
assertThat(committer.email).isEqualTo(admin.email);
@@ -2060,15 +2066,13 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(result.actions).isNull();
assertThat(result.revisions).isNull();
EnumSet<ListChangesOption> options =
EnumSet.of(
ListChangesOption.ALL_REVISIONS,
ListChangesOption.CHANGE_ACTIONS,
ListChangesOption.CURRENT_ACTIONS,
ListChangesOption.DETAILED_LABELS,
ListChangesOption.MESSAGES);
result =
Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOptions(options).get());
Iterables.getOnlyElement(
gApi.changes()
.query(r.getChangeId())
.withOptions(
ALL_REVISIONS, CHANGE_ACTIONS, CURRENT_ACTIONS, DETAILED_LABELS, MESSAGES)
.get());
assertThat(Iterables.getOnlyElement(result.labels.keySet())).isEqualTo("Code-Review");
assertThat(result.messages).hasSize(1);
assertThat(result.actions).isNotEmpty();
@@ -2194,8 +2198,7 @@ public class ChangeIT extends AbstractDaemonTest {
public void check() throws Exception {
PushOneCommit.Result r = createChange();
assertThat(gApi.changes().id(r.getChangeId()).get().problems).isNull();
assertThat(gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.CHECK)).problems)
.isEmpty();
assertThat(gApi.changes().id(r.getChangeId()).get(CHECK).problems).isEmpty();
}
@Test
@@ -2233,9 +2236,7 @@ public class ChangeIT extends AbstractDaemonTest {
in.label("Custom2", 1);
gApi.changes().id(r2.getChangeId()).current().review(in);
EnumSet<ListChangesOption> options =
EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.COMMIT_FOOTERS);
ChangeInfo actual = gApi.changes().id(r2.getChangeId()).get(options);
ChangeInfo actual = gApi.changes().id(r2.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
assertThat(actual.revisions).hasSize(2);
// No footers except on latest patch set.
@@ -2278,9 +2279,7 @@ public class ChangeIT extends AbstractDaemonTest {
});
ChangeInfo actual;
try {
EnumSet<ListChangesOption> options =
EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.COMMIT_FOOTERS);
actual = gApi.changes().id(change.getChangeId()).get(options);
actual = gApi.changes().id(change.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
} finally {
handle.remove();
}
@@ -2321,9 +2320,9 @@ public class ChangeIT extends AbstractDaemonTest {
.query()
.withQuery("project:{" + project.get() + "} (status:open OR status:closed)")
// Options should match defaults in AccountDashboardScreen.
.withOption(ListChangesOption.LABELS)
.withOption(ListChangesOption.DETAILED_ACCOUNTS)
.withOption(ListChangesOption.REVIEWED)
.withOption(LABELS)
.withOption(DETAILED_ACCOUNTS)
.withOption(REVIEWED)
.get())
.hasSize(2);
} finally {
@@ -2336,7 +2335,7 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId();
gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0);
@@ -2346,7 +2345,7 @@ public class ChangeIT extends AbstractDaemonTest {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
Util.blockLabel(cfg, "Code-Review", REGISTERED_USERS, "refs/heads/*");
saveProjectConfig(project, cfg);
c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
c = gApi.changes().id(triplet).get(DETAILED_LABELS);
codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
approval = codeReview.all.get(0);
@@ -2361,10 +2360,7 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r1 = createChange();
PushOneCommit.Result r2 = amendChange(r1.getChangeId());
ChangeInfo info =
gApi.changes()
.id(r1.getChangeId())
.get(EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.PUSH_CERTIFICATES));
ChangeInfo info = gApi.changes().id(r1.getChangeId()).get(ALL_REVISIONS, PUSH_CERTIFICATES);
RevisionInfo rev1 = info.revisions.get(r1.getCommit().name());
assertThat(rev1).isNotNull();
@@ -2676,13 +2672,7 @@ public class ChangeIT extends AbstractDaemonTest {
in.subject = "update change by merge ps2";
gApi.changes().id(changeId).createMergePatchSet(in);
ChangeInfo changeInfo =
gApi.changes()
.id(changeId)
.get(
EnumSet.of(
ListChangesOption.ALL_REVISIONS,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.CURRENT_REVISION));
gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(changeInfo.revisions.size()).isEqualTo(2);
assertThat(changeInfo.subject).isEqualTo(in.subject);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit)
@@ -2719,13 +2709,7 @@ public class ChangeIT extends AbstractDaemonTest {
in.inheritParent = true;
gApi.changes().id(changeId).createMergePatchSet(in);
ChangeInfo changeInfo =
gApi.changes()
.id(changeId)
.get(
EnumSet.of(
ListChangesOption.ALL_REVISIONS,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.CURRENT_REVISION));
gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(changeInfo.revisions.size()).isEqualTo(2);
assertThat(changeInfo.subject).isEqualTo(in.subject);
@@ -2931,7 +2915,7 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0);
@@ -2951,7 +2935,7 @@ public class ChangeIT extends AbstractDaemonTest {
heads);
saveProjectConfig(project, cfg);
c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
c = gApi.changes().id(triplet).get(DETAILED_LABELS);
codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
approval = codeReview.all.get(0);
@@ -2972,7 +2956,7 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0);
@@ -3156,14 +3140,7 @@ public class ChangeIT extends AbstractDaemonTest {
ri.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(ci));
gApi.changes().id(id).current().review(ri);
ChangeInfo info =
gApi.changes()
.id(id)
.get(
EnumSet.of(
ListChangesOption.MESSAGES,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.CURRENT_REVISION));
ChangeInfo info = gApi.changes().id(id).get(MESSAGES, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(info.subject).isEqualTo(subject);
assertThat(Iterables.getLast(info.messages).message).endsWith(ri.message);
assertThat(Iterables.getOnlyElement(info.revisions.values()).commit.message)
@@ -3311,7 +3288,7 @@ public class ChangeIT extends AbstractDaemonTest {
private Optional<ReviewerState> getReviewerState(String changeId, Account.Id accountId)
throws Exception {
ChangeInfo c = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo c = gApi.changes().id(changeId).get(DETAILED_LABELS);
Set<ReviewerState> states =
c.reviewers
.entrySet()
@@ -3372,8 +3349,7 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus();
ChangeInfo change =
gApi.changes().id(result.getChangeId()).get(EnumSet.of(ListChangesOption.TRACKING_IDS));
ChangeInfo change = gApi.changes().id(result.getChangeId()).get(TRACKING_IDS);
Collection<TrackingIdInfo> trackingIds = change.trackingIds;
assertThat(trackingIds).isNotNull();
assertThat(trackingIds).hasSize(1);

View File

@@ -20,6 +20,9 @@ import static com.google.gerrit.extensions.client.ChangeKind.NO_CHANGE;
import static com.google.gerrit.extensions.client.ChangeKind.NO_CODE_CHANGE;
import static com.google.gerrit.extensions.client.ChangeKind.REWORK;
import static com.google.gerrit.extensions.client.ChangeKind.TRIVIAL_REBASE;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
import static com.google.gerrit.server.project.Util.category;
import static com.google.gerrit.server.project.Util.value;
@@ -38,7 +41,6 @@ import com.google.gerrit.extensions.api.changes.CherryPickInput;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.CommitInfo;
@@ -336,13 +338,7 @@ public class StickyApprovalsIT extends AbstractDaemonTest {
}
private ChangeInfo detailedChange(String changeId) throws Exception {
return gApi.changes()
.id(changeId)
.get(
EnumSet.of(
ListChangesOption.DETAILED_LABELS,
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT));
return gApi.changes().id(changeId).get(DETAILED_LABELS, CURRENT_REVISION, CURRENT_COMMIT);
}
private void assertNotSticky(Set<ChangeKind> changeKinds) throws Exception {
@@ -533,7 +529,7 @@ public class StickyApprovalsIT extends AbstractDaemonTest {
}
private ChangeKind getChangeKind(String changeId) throws Exception {
ChangeInfo c = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.CURRENT_REVISION));
ChangeInfo c = gApi.changes().id(changeId).get(CURRENT_REVISION);
return c.revisions.get(c.currentRevision).kind;
}

View File

@@ -53,7 +53,6 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput;
import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.SubmitType;
import com.google.gerrit.extensions.common.AccountInfo;
@@ -92,7 +91,6 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -162,8 +160,7 @@ public class RevisionIT extends AbstractDaemonTest {
approval = getApproval(changeId, label);
assertThat(approval.value).isEqualTo(1);
assertThat(approval.postSubmit).isNull();
assertPermitted(
gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)), "Code-Review", 1, 2);
assertPermitted(gApi.changes().id(changeId).get(DETAILED_LABELS), "Code-Review", 1, 2);
// Repeating the current label is allowed. Does not flip the postSubmit bit
// due to deduplication codepath.
@@ -190,7 +187,7 @@ public class RevisionIT extends AbstractDaemonTest {
approval = getApproval(changeId, label);
assertThat(approval.value).isEqualTo(2);
assertThat(approval.postSubmit).isTrue();
assertPermitted(gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)), "Code-Review", 2);
assertPermitted(gApi.changes().id(changeId).get(DETAILED_LABELS), "Code-Review", 2);
// Decreasing to previous post-submit vote is still not allowed.
try {
@@ -241,7 +238,7 @@ public class RevisionIT extends AbstractDaemonTest {
ApprovalInfo cr =
gApi.changes()
.id(changeId)
.get(EnumSet.of(ListChangesOption.DETAILED_LABELS))
.get(DETAILED_LABELS)
.labels
.get("Code-Review")
.all
@@ -1359,7 +1356,7 @@ public class RevisionIT extends AbstractDaemonTest {
}
private ApprovalInfo getApproval(String changeId, String label) throws Exception {
ChangeInfo info = gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS));
ChangeInfo info = gApi.changes().id(changeId).get(DETAILED_LABELS);
LabelInfo li = info.labels.get(label);
assertThat(li).isNotNull();
int accountId = atrScope.get().getUser().getAccountId().get();

View File

@@ -22,6 +22,8 @@ import static com.google.gerrit.acceptance.GitUtil.assertPushRejected;
import static com.google.gerrit.acceptance.GitUtil.pushHead;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
import static com.google.gerrit.common.FooterConstants.CHANGE_ID;
import static com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.extensions.common.EditInfoSubject.assertThat;
import static com.google.gerrit.server.git.receive.ReceiveConstants.PUSH_OPTION_SKIP_VALIDATION;
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
@@ -1630,8 +1632,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
String ref = "refs/for/master%merged";
assertPushOk(pushHead(testRepo, ref, false), ref);
EnumSet<ListChangesOption> opts = EnumSet.of(ListChangesOption.ALL_REVISIONS);
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(opts);
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(ALL_REVISIONS);
assertThat(info.currentRevision).isEqualTo(c2.name());
assertThat(info.revisions.keySet()).containsExactly(c1.name(), c2.name());
// TODO(dborowitz): Fix ReceiveCommits to also auto-close the change.
@@ -1839,12 +1840,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
private String getLastMessage(String changeId) throws Exception {
return Streams.findLast(
gApi.changes()
.id(changeId)
.get(EnumSet.of(ListChangesOption.MESSAGES))
.messages
.stream()
.map(m -> m.message))
gApi.changes().id(changeId).get(MESSAGES).messages.stream().map(m -> m.message))
.get();
}

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.account;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
@@ -39,7 +40,6 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput;
import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.changes.SubmitInput;
import com.google.gerrit.extensions.api.groups.GroupInput;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
@@ -64,7 +64,6 @@ import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.Util;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.inject.Inject;
import java.util.EnumSet;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.junit.After;
@@ -545,8 +544,7 @@ public class ImpersonationIT extends AbstractDaemonTest {
setApiUser(accountCreator.user2());
gApi.changes().id(r.getChangeId()).revision(r.getPatchSetId().getId()).review(in);
ChangeInfo info =
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.MESSAGES));
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(MESSAGES);
assertThat(info.messages).hasSize(2);
ChangeMessageInfo changeMessageInfo = Iterables.getLast(info.messages);

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.acceptance.rest.change;
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.extensions.client.ListChangesOption.CHANGE_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
@@ -316,7 +317,7 @@ public class ActionsIT extends AbstractDaemonTest {
@Test
public void changeActionVisitor() throws Exception {
String id = createChange().getChangeId();
ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS));
ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
class Visitor implements ActionVisitor {
@Override
@@ -362,7 +363,7 @@ public class ActionsIT extends AbstractDaemonTest {
public void currentRevisionActionVisitor() throws Exception {
String id = createChange().getChangeId();
amendChange(id);
ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS));
ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
Change.Id changeId = new Change.Id(origChange._number);
class Visitor implements ActionVisitor {
@@ -429,7 +430,7 @@ public class ActionsIT extends AbstractDaemonTest {
public void oldRevisionActionVisitor() throws Exception {
String id = createChange().getChangeId();
amendChange(id);
ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS));
ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
class Visitor implements ActionVisitor {
@Override

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.change;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -28,13 +29,11 @@ import com.google.gerrit.extensions.api.changes.AddReviewerResult;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.projects.ConfigInput;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.server.mail.Address;
import com.google.gerrit.testutil.FakeEmailSender.Message;
import java.util.EnumSet;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -62,8 +61,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
input.state = state;
gApi.changes().id(r.getChangeId()).addReviewer(input);
ChangeInfo info =
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc)));
// All reviewers added by email should be removable
assertThat(info.removableReviewers).isEqualTo(ImmutableList.of(acc));
@@ -89,8 +87,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
inputById.state = state;
gApi.changes().id(r.getChangeId()).addReviewer(inputById);
ChangeInfo info =
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(byId, byEmail)));
// All reviewers (both by id and by email) should be removable
assertThat(info.removableReviewers).isEqualTo(ImmutableList.of(byId, byEmail));
@@ -112,8 +109,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
gApi.changes().id(r.getChangeId()).reviewer(acc.email).remove();
ChangeInfo info =
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
assertThat(info.reviewers).isEmpty();
}
}
@@ -135,8 +131,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
modifyInput.state = ReviewerState.REVIEWER;
gApi.changes().id(r.getChangeId()).addReviewer(modifyInput);
ChangeInfo info =
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
assertThat(info.reviewers)
.isEqualTo(ImmutableMap.of(ReviewerState.REVIEWER, ImmutableList.of(acc)));
}
@@ -329,10 +324,7 @@ public class ChangeReviewersByEmailIT extends AbstractDaemonTest {
try {
ChangeInfo info =
Iterables.getOnlyElement(
gApi.changes()
.query(r.getChangeId())
.withOption(ListChangesOption.DETAILED_LABELS)
.get());
gApi.changes().query(r.getChangeId()).withOption(DETAILED_LABELS).get());
assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc)));
} finally {
notesMigration.setFailOnLoadForTest(false);

View File

@@ -48,7 +48,6 @@ import com.google.gerrit.testutil.FakeEmailSender.Message;
import com.google.gson.stream.JsonReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -806,6 +805,6 @@ public class ChangeReviewersIT extends AbstractDaemonTest {
}
private Map<String, LabelInfo> getChangeLabels(String changeId) throws Exception {
return gApi.changes().id(changeId).get(EnumSet.of(DETAILED_LABELS)).labels;
return gApi.changes().id(changeId).get(DETAILED_LABELS).labels;
}
}

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static java.util.stream.Collectors.toList;
import com.google.common.collect.Iterables;
@@ -26,7 +27,6 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.update.BatchUpdate;
@@ -39,7 +39,6 @@ import com.google.gerrit.testutil.ConfigSuite;
import com.google.inject.Inject;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
@@ -280,7 +279,7 @@ public class NoteDbOnlyIT extends AbstractDaemonTest {
private List<String> getMessages(Change.Id id) throws Exception {
return gApi.changes()
.id(id.get())
.get(EnumSet.of(ListChangesOption.MESSAGES))
.get(MESSAGES)
.messages
.stream()
.map(m -> m.message)

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.extensions.api.changes;
import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo;
@@ -27,6 +28,7 @@ import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.extensions.common.SuggestedReviewerInfo;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.RestApiException;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -170,6 +172,14 @@ public interface ChangeApi {
ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException;
default ChangeInfo get(Iterable<ListChangesOption> options) throws RestApiException {
return get(Sets.newEnumSet(options, ListChangesOption.class));
}
default ChangeInfo get(ListChangesOption... options) throws RestApiException {
return get(Arrays.asList(options));
}
/** {@code get} with {@link ListChangesOption} set to all except CHECK. */
ChangeInfo get() throws RestApiException;
/** {@code get} with {@link ListChangesOption} set to none. */