use of com.google.gerrit.extensions.common.FixReplacementInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method fixSuggestionCannotPointToPatchsetLevel.
@Test
public void fixSuggestionCannotPointToPatchsetLevel() throws Exception {
RobotCommentInput input = TestCommentHelper.createRobotCommentInput(FILE_NAME);
FixReplacementInfo brokenFixReplacement = createFixReplacementInfo();
brokenFixReplacement.path = PATCHSET_LEVEL;
input.fixSuggestions = ImmutableList.of(createFixSuggestionInfo(brokenFixReplacement));
BadRequestException ex = assertThrows(BadRequestException.class, () -> testCommentHelper.addRobotComment(changeId, input));
assertThat(ex.getMessage()).contains("file path must not be " + PATCHSET_LEVEL);
}
use of com.google.gerrit.extensions.common.FixReplacementInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method rangesOfFixReplacementsOfDifferentFixSuggestionsForSameFileMayOverlap.
@Test
public void rangesOfFixReplacementsOfDifferentFixSuggestionsForSameFileMayOverlap() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 1);
fixReplacementInfo1.replacement = "First modification\n";
FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME;
fixReplacementInfo2.range = createRange(3, 0, 4, 0);
fixReplacementInfo2.replacement = "Second modification\n";
FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo1, fixSuggestionInfo2);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
assertThatList(robotCommentInfos).onlyElement().fixSuggestions().hasSize(2);
}
use of com.google.gerrit.extensions.common.FixReplacementInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method fixReplacementsDoNotNeedToBeOrderedAccordingToRange.
@Test
public void fixReplacementsDoNotNeedToBeOrderedAccordingToRange() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 0);
fixReplacementInfo1.replacement = "First modification\n";
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME;
fixReplacementInfo2.range = createRange(3, 0, 4, 0);
fixReplacementInfo2.replacement = "Second modification\n";
FixReplacementInfo fixReplacementInfo3 = new FixReplacementInfo();
fixReplacementInfo3.path = FILE_NAME;
fixReplacementInfo3.range = createRange(4, 0, 5, 0);
fixReplacementInfo3.replacement = "Third modification\n";
FixSuggestionInfo fixSuggestionInfo = createFixSuggestionInfo(fixReplacementInfo2, fixReplacementInfo1, fixReplacementInfo3);
withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
assertThatList(robotCommentInfos).onlyElement().onlyFixSuggestion().replacements().hasSize(3);
}
use of com.google.gerrit.extensions.common.FixReplacementInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method twoConflictingFixesOnSameFileCannotBeApplied.
@Test
public void twoConflictingFixesOnSameFileCannotBeApplied() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 1);
fixReplacementInfo1.replacement = "First modification\n";
FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME;
fixReplacementInfo2.range = createRange(3, 0, 4, 0);
fixReplacementInfo2.replacement = "Some other modified content\n";
FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
RobotCommentInput robotCommentInput1 = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo1);
RobotCommentInput robotCommentInput2 = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo2);
testCommentHelper.addRobotComment(changeId, robotCommentInput1);
testCommentHelper.addRobotComment(changeId, robotCommentInput2);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
gApi.changes().id(changeId).current().applyFix(fixIds.get(0));
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().applyFix(fixIds.get(1)));
assertThat(thrown).hasMessageThat().contains("merge");
}
use of com.google.gerrit.extensions.common.FixReplacementInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method fixInvolvingTwoFilesCanBeApplied.
@Test
public void fixInvolvingTwoFilesCanBeApplied() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 0);
fixReplacementInfo1.replacement = "First modification\n";
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME2;
fixReplacementInfo2.range = createRange(1, 0, 2, 0);
fixReplacementInfo2.replacement = "Different file modification\n";
FixSuggestionInfo fixSuggestionInfo = createFixSuggestionInfo(fixReplacementInfo1, fixReplacementInfo2);
withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
String fixId = Iterables.getOnlyElement(fixIds);
gApi.changes().id(changeId).current().applyFix(fixId);
Optional<BinaryResult> file = gApi.changes().id(changeId).edit().getFile(FILE_NAME);
BinaryResultSubject.assertThat(file).value().asString().isEqualTo("First line\nFirst modification\nThird line\nFourth line\nFifth line\nSixth line\n" + "Seventh line\nEighth line\nNinth line\nTenth line\n");
Optional<BinaryResult> file2 = gApi.changes().id(changeId).edit().getFile(FILE_NAME2);
BinaryResultSubject.assertThat(file2).value().asString().isEqualTo("Different file modification\n2nd line\n3rd line\n");
}
Aggregations