use of com.google.gerrit.entities.Patch in project gerrit by GerritCodeReview.
the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedUpInLatestPatchSet.
@Test
public void rebaseHunkIsIdentifiedWhenMovedUpInLatestPatchSet() throws Exception {
String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
// Move the code up by removing lines (pure deletion + shrinking replacement) in the latest
// patch set.
Function<String, String> contentModification = fileContent -> fileContent.replace("Line 1\n", "").replace("Line 10\nLine 11\n", "Line ten\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
assertThat(diffInfo).content().element(0).linesOfA().containsExactly("Line 1");
assertThat(diffInfo).content().element(0).linesOfB().isNull();
assertThat(diffInfo).content().element(0).isNotDueToRebase();
assertThat(diffInfo).content().element(1).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 10", "Line 11");
assertThat(diffInfo).content().element(2).linesOfB().containsExactly("Line ten");
assertThat(diffInfo).content().element(2).isNotDueToRebase();
assertThat(diffInfo).content().element(3).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(4).isDueToRebase();
assertThat(diffInfo).content().element(5).commonLines().isNotEmpty();
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(3);
}
use of com.google.gerrit.entities.Patch in project gerrit by GerritCodeReview.
the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedUpInPreviousPatchSet.
@Test
public void rebaseHunkIsIdentifiedWhenMovedUpInPreviousPatchSet() throws Exception {
// Move the code up by removing lines (pure deletion + shrinking replacement) in the previous
// patch set.
Function<String, String> contentModification1 = fileContent -> fileContent.replace("Line 1\n", "").replace("Line 10\nLine 11\n", "Line ten\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification1);
String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
Function<String, String> contentModification2 = fileContent -> fileContent.replace("Line 100\n", "Line one hundred\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification2);
DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(previousPatchSetId).get();
assertThat(diffInfo).content().element(0).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(1).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(1).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(1).isDueToRebase();
assertThat(diffInfo).content().element(2).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(3).linesOfA().containsExactly("Line 100");
assertThat(diffInfo).content().element(3).linesOfB().containsExactly("Line one hundred");
assertThat(diffInfo).content().element(3).isNotDueToRebase();
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(previousPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
use of com.google.gerrit.entities.Patch in project gerrit by GerritCodeReview.
the class RobotCommentsIT method addedRobotCommentsAreLinkedToChangeMessages.
@UseClockStep
@Test
public void addedRobotCommentsAreLinkedToChangeMessages() throws Exception {
// Advancing the time after creating the change so that the first robot comment is not in the
// same timestamp as with the change creation.
TestTimeUtil.incrementClock(10, TimeUnit.SECONDS);
RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c3 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
// Give the robot comments identifiable names for testing
c1.message = "robot comment 1";
c2.message = "robot comment 2";
c3.message = "robot comment 3";
testCommentHelper.addRobotComment(changeId, c1, "robot message 1");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c2, "robot message 2");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c3, "robot message 3");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
Map<String, List<RobotCommentInfo>> robotComments = gApi.changes().id(changeId).robotComments();
List<RobotCommentInfo> robotCommentsList = robotComments.values().stream().flatMap(List::stream).collect(toList());
List<ChangeMessageInfo> allMessages = gApi.changes().id(changeId).get(MESSAGES).messages.stream().collect(toList());
assertThat(allMessages.stream().map(cm -> cm.message).collect(toList())).containsExactly("Uploaded patch set 1.", "Patch Set 1:\n\n(1 comment)\n\nrobot message 1", "Patch Set 1:\n\n(1 comment)\n\nrobot message 2", "Patch Set 1:\n\n(1 comment)\n\nrobot message 3");
assertThat(robotCommentsList.stream().map(c -> c.message).collect(toList())).containsExactly("robot comment 1", "robot comment 2", "robot comment 3");
String message1ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 1")).collect(onlyElement()).id;
String message2ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 2")).collect(onlyElement()).id;
String message3ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 3")).collect(onlyElement()).id;
String comment1MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 1")).collect(onlyElement()).changeMessageId;
String comment2MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 2")).collect(onlyElement()).changeMessageId;
String comment3MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 3")).collect(onlyElement()).changeMessageId;
/**
* All change messages have the auto-generated tag. Robot comments can be linked to
* auto-generated messages where each comment is linked to the next nearest change message in
* timestamp
*/
assertThat(message1ChangeId).isEqualTo(comment1MessageId);
assertThat(message2ChangeId).isEqualTo(comment2MessageId);
assertThat(message3ChangeId).isEqualTo(comment3MessageId);
}
use of com.google.gerrit.entities.Patch in project gerrit by GerritCodeReview.
the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedDownInPreviousPatchSet.
@Test
public void rebaseHunkIsIdentifiedWhenMovedDownInPreviousPatchSet() throws Exception {
// Move the code down by introducing additional lines (pure insert + enlarging replacement) in
// the previous patch set.
Function<String, String> contentModification1 = fileContent -> "Line zero\n" + fileContent.replace("Line 10\n", "Line ten\nLine ten and a half\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification1);
String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
Function<String, String> contentModification2 = fileContent -> fileContent.replace("Line 100\n", "Line one hundred\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification2);
DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(previousPatchSetId).get();
assertThat(diffInfo).content().element(0).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(1).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(1).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(1).isDueToRebase();
assertThat(diffInfo).content().element(2).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(3).linesOfA().containsExactly("Line 100");
assertThat(diffInfo).content().element(3).linesOfB().containsExactly("Line one hundred");
assertThat(diffInfo).content().element(3).isNotDueToRebase();
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(previousPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
use of com.google.gerrit.entities.Patch in project gerrit by GerritCodeReview.
the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedDownInLatestPatchSet.
@Test
public void rebaseHunkIsIdentifiedWhenMovedDownInLatestPatchSet() throws Exception {
String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
// Move the code down by introducing additional lines (pure insert + enlarging replacement) in
// the latest patch set.
Function<String, String> contentModification = fileContent -> "Line zero\n" + fileContent.replace("Line 10\n", "Line ten\nLine ten and a half\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
assertThat(diffInfo).content().element(0).linesOfA().isNull();
assertThat(diffInfo).content().element(0).linesOfB().containsExactly("Line zero");
assertThat(diffInfo).content().element(0).isNotDueToRebase();
assertThat(diffInfo).content().element(1).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 10");
assertThat(diffInfo).content().element(2).linesOfB().containsExactly("Line ten", "Line ten and a half");
assertThat(diffInfo).content().element(2).isNotDueToRebase();
assertThat(diffInfo).content().element(3).commonLines().isNotEmpty();
assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(4).isDueToRebase();
assertThat(diffInfo).content().element(5).commonLines().isNotEmpty();
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(3);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
Aggregations