PatchSetApproval: Convert getTag to return Optional
Change-Id: Ifaa21dcc8b8a826a7f59df19d04dc9a737a1ff0d
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.gerrit.common.Nullable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/** An approval (or negative approval) on a patch set. */
|
||||
public final class PatchSetApproval {
|
||||
@@ -154,8 +155,8 @@ public final class PatchSetApproval {
|
||||
return LabelId.LEGACY_SUBMIT_NAME.equals(getLabel());
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
public Optional<String> getTag() {
|
||||
return Optional.ofNullable(tag);
|
||||
}
|
||||
|
||||
public void setPostSubmit(boolean postSubmit) {
|
||||
|
||||
@@ -39,10 +39,7 @@ public enum PatchSetApprovalProtoConverter
|
||||
.setGranted(patchSetApproval.getGranted().getTime())
|
||||
.setPostSubmit(patchSetApproval.isPostSubmit());
|
||||
|
||||
String tag = patchSetApproval.getTag();
|
||||
if (tag != null) {
|
||||
builder.setTag(tag);
|
||||
}
|
||||
patchSetApproval.getTag().ifPresent(builder::setTag);
|
||||
Account.Id realAccountId = patchSetApproval.getRealAccountId();
|
||||
// PatchSetApproval#getRealAccountId automatically delegates to PatchSetApproval#getAccountId if
|
||||
// the real author is not set. However, the previous protobuf representation kept
|
||||
|
||||
@@ -599,7 +599,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
approval.getAccountId().get(),
|
||||
Integer.valueOf(approval.getValue()),
|
||||
null,
|
||||
approval.getTag(),
|
||||
approval.getTag().orElse(null),
|
||||
approval.getGranted());
|
||||
accountLoader.put(info);
|
||||
result.get(label).add(info);
|
||||
|
||||
@@ -346,7 +346,7 @@ public class LabelsJson {
|
||||
info.value = Integer.valueOf(val);
|
||||
info.permittedVotingRange = pvr.getOrDefault(type.getName(), null);
|
||||
info.date = psa.getGranted();
|
||||
info.tag = psa.getTag();
|
||||
info.tag = psa.getTag().orElse(null);
|
||||
if (psa.isPostSubmit()) {
|
||||
info.postSubmit = true;
|
||||
}
|
||||
@@ -474,7 +474,7 @@ public class LabelsJson {
|
||||
// label.
|
||||
value = perm.test(new LabelPermission(lt)) ? 0 : null;
|
||||
}
|
||||
tag = psa.getTag();
|
||||
tag = psa.getTag().orElse(null);
|
||||
date = psa.getGranted();
|
||||
if (psa.isPostSubmit()) {
|
||||
logger.atWarning().log("unexpected post-submit approval on open change: %s", psa);
|
||||
|
||||
@@ -163,7 +163,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
|
||||
ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals = notes.getApprovals();
|
||||
assertThat(approvals).hasSize(1);
|
||||
assertThat(approvals.entries().asList().get(0).getValue().getTag()).isEqualTo(tag2);
|
||||
assertThat(approvals.entries().asList().get(0).getValue().getTag()).hasValue(tag2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,7 +210,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals = notes.getApprovals();
|
||||
assertThat(approvals).hasSize(1);
|
||||
PatchSetApproval approval = approvals.entries().asList().get(0).getValue();
|
||||
assertThat(approval.getTag()).isEqualTo(integrationTag);
|
||||
assertThat(approval.getTag()).hasValue(integrationTag);
|
||||
assertThat(approval.getValue()).isEqualTo(-1);
|
||||
|
||||
ImmutableListMultimap<ObjectId, Comment> comments = notes.getComments();
|
||||
|
||||
Reference in New Issue
Block a user