Refactor TestCommentHelper in preparation for limiting comment count

This prepares If24adc10f5f16cd8894bf246078f0e6c992cdafa

Change-Id: Iffdceb55b8204204fa8a98b84c5740112105e09e
This commit is contained in:
Joerg Zieren
2020-01-02 10:18:14 +01:00
parent d0977d135e
commit e4f08c6418
2 changed files with 131 additions and 107 deletions

View File

@@ -16,14 +16,21 @@ package com.google.gerrit.testing;
import static java.util.stream.Collectors.toList;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.api.changes.DraftInput;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput;
import com.google.gerrit.extensions.client.Comment;
import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.common.FixSuggestionInfo;
import com.google.inject.Inject;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
/** Test helper for dealing with comments/drafts. */
public class TestCommentHelper {
@@ -44,7 +51,7 @@ public class TestCommentHelper {
}
public void addDraft(String changeId, String revId, DraftInput in) throws Exception {
gApi.changes().id(changeId).revision(revId).createDraft(in).get();
gApi.changes().id(changeId).revision(revId).createDraft(in);
}
public Collection<CommentInfo> getPublishedComments(String changeId) throws Exception {
@@ -104,4 +111,34 @@ public class TestCommentHelper {
range.endCharacter = 5;
return range;
}
public static RobotCommentInput createRobotCommentInputWithMandatoryFields(String path) {
RobotCommentInput in = new RobotCommentInput();
in.robotId = "happyRobot";
in.robotRunId = "1";
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = path;
return in;
}
public static RobotCommentInput createRobotCommentInput(
String path, FixSuggestionInfo... fixSuggestionInfos) {
RobotCommentInput in = TestCommentHelper.createRobotCommentInputWithMandatoryFields(path);
in.url = "http://www.happy-robot.com";
in.properties = new HashMap<>();
in.properties.put("key1", "value1");
in.properties.put("key2", "value2");
in.fixSuggestions = Arrays.asList(fixSuggestionInfos);
return in;
}
public void addRobotComment(String targetChangeId, RobotCommentInput robotCommentInput)
throws Exception {
ReviewInput reviewInput = new ReviewInput();
reviewInput.robotComments =
Collections.singletonMap(robotCommentInput.path, ImmutableList.of(robotCommentInput));
reviewInput.message = "robot comment test";
gApi.changes().id(targetChangeId).current().review(reviewInput);
}
}