use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class CommentPorterTest method commentsWithInvalidPatchsetsAreIgnored.
@Test
public void commentsWithInvalidPatchsetsAreIgnored() throws Exception {
Project.NameKey project = Project.nameKey("myProject");
Change.Id changeId = Change.id(1);
Change change = createChange(project, changeId);
PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
// Leave out patchset 1 (e.g. reserved for draft patchsets in the past).
ChangeNotes changeNotes = mockChangeNotes(project, change, patchset2);
CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
HumanComment comment = createComment(patchset1.id(), "myFile");
when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenReturn(ImmutableMap.of());
ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
assertThat(portedComments).isEmpty();
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class CommentPorterTest method commentsAreStillPortedWhenDiffOfOtherCommentsHasError.
@Test
public void commentsAreStillPortedWhenDiffOfOtherCommentsHasError() throws Exception {
Project.NameKey project = Project.nameKey("myProject");
Change.Id changeId = Change.id(1);
Change change = createChange(project, changeId);
PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
PatchSet patchset3 = createPatchset(PatchSet.id(changeId, 3));
ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2, patchset3);
CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
// Place the comments on different patchsets to have two different diff requests.
HumanComment comment1 = createComment(patchset1.id(), "myFile");
HumanComment comment2 = createComment(patchset2.id(), "myFile");
when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
// Throw an exception on the first diff request but return an actual value on the second.
when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(IllegalStateException.class).thenReturn(ImmutableMap.of());
ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset3, ImmutableList.of(comment1, comment2), ImmutableList.of());
// One of the comments should still be ported as usual. -> Keeps its file name as the diff was
// empty.
assertThat(portedComments).comparingElementsUsing(hasFilePath()).contains("myFile");
}
Aggregations