Search in sources :

Example 21 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedRangeCommentStartingWithinLastModifiedLineBecomesFileComment.

@Test
public void portedRangeCommentStartingWithinLastModifiedLineBecomesFileComment() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").content("Line one\nLine two\nLine 3\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).fromLine(2).charOffset(2).toLine(4).charOffset(5).ofFile("myFile").create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).range().isNull();
    assertThat(portedComment).line().isNull();
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 22 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedLineCommentCanHandleDeletedLines.

@Test
public void portedLineCommentCanHandleDeletedLines() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").content("Line 2\nLine 3\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).onLine(3).ofFile("myFile").create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).line().isEqualTo(2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 23 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedRangeCommentBecomesFileCommentOnConflict.

@Test
public void portedRangeCommentBecomesFileCommentOnConflict() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").content("Line 1\nLine two\nLine three\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).fromLine(2).charOffset(2).toLine(3).charOffset(5).ofFile("myFile").create();
    Map<String, List<CommentInfo>> portedComments = getPortedComments(patchset2Id);
    assertThatMap(portedComments).keys().containsExactly("myFile");
    CommentInfo portedComment = extractSpecificComment(portedComments, commentUuid);
    assertThat(portedComment).range().isNull();
    assertThat(portedComment).line().isNull();
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList) List(java.util.List) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 24 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedRangeCommentAdditionallyAppearsOnCopyAtIndependentPosition.

@Test
public void portedRangeCommentAdditionallyAppearsOnCopyAtIndependentPosition() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    // Gerrit currently only identifies a copy if a rename also happens at the same time. Modify the
    // renamed file slightly different than the copied file so that the end location of the comment
    // is different. Modify the renamed file less so that Gerrit/Git picks it as the renamed one.
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").delete().file("renamedFiled").content("Line 1\nLine 1.1\nLine 2\nLine 3\nLine 4\n").file("copiedFile").content("Line 1\nLine 1.1\nLine 1.2\nLine 2\nLine 3\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).fromLine(3).charOffset(2).toLine(4).charOffset(5).ofFile("myFile").create();
    Map<String, List<CommentInfo>> portedComments = getPortedComments(patchset2Id);
    assertThatMap(portedComments).keys().containsExactly("renamedFiled", "copiedFile");
    CommentInfo portedCommentOnRename = getOnlyElement(portedComments.get("renamedFiled"));
    assertThat(portedCommentOnRename).uuid().isEqualTo(commentUuid);
    assertThat(portedCommentOnRename).range().startLine().isEqualTo(4);
    assertThat(portedCommentOnRename).range().startCharacter().isEqualTo(2);
    assertThat(portedCommentOnRename).range().endLine().isEqualTo(5);
    assertThat(portedCommentOnRename).range().endCharacter().isEqualTo(5);
    CommentInfo portedCommentOnCopy = getOnlyElement(portedComments.get("copiedFile"));
    assertThat(portedCommentOnCopy).uuid().isEqualTo(commentUuid);
    assertThat(portedCommentOnCopy).range().startLine().isEqualTo(5);
    assertThat(portedCommentOnCopy).range().startCharacter().isEqualTo(2);
    assertThat(portedCommentOnCopy).range().endLine().isEqualTo(6);
    assertThat(portedCommentOnCopy).range().endCharacter().isEqualTo(5);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList) List(java.util.List) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 25 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedLineCommentOnLineJustBeforeModificationCanBePorted.

@Test
public void portedLineCommentOnLineJustBeforeModificationCanBePorted() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").content("Line 1\nLine 2\nLine three\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).onLine(2).ofFile("myFile").create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).line().isEqualTo(2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Change (com.google.gerrit.entities.Change)659 Test (org.junit.Test)510 PatchSet (com.google.gerrit.entities.PatchSet)167 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)165 ObjectId (org.eclipse.jgit.lib.ObjectId)113 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)112 RevCommit (org.eclipse.jgit.revwalk.RevCommit)88 Account (com.google.gerrit.entities.Account)83 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)72 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)66 List (java.util.List)64 ImmutableList (com.google.common.collect.ImmutableList)63 ChangeData (com.google.gerrit.server.query.change.ChangeData)60 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)58 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)56 Instant (java.time.Instant)54 Project (com.google.gerrit.entities.Project)52 StorageException (com.google.gerrit.exceptions.StorageException)50 Ref (org.eclipse.jgit.lib.Ref)49 HumanComment (com.google.gerrit.entities.HumanComment)46