Search in sources :

Example 11 with TreeModification

use of com.google.gerrit.server.edit.tree.TreeModification in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method replacementsCanDeleteALine.

@Test
public void replacementsCanDeleteALine() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(2, 0, 3, 0), "");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First line\nThird line\n");
}
Also used : TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Example 12 with TreeModification

use of com.google.gerrit.server.edit.tree.TreeModification in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method replacementsMayOccurOnSameLine.

@Test
public void replacementsMayOccurOnSameLine() throws Exception {
    FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(2, 0, 2, 6), "A");
    FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(2, 7, 2, 11), "modification");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement1, fixReplacement2);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First line\nA modification\nThird line\n");
}
Also used : TreeModification(com.google.gerrit.server.edit.tree.TreeModification) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Aggregations

TreeModification (com.google.gerrit.server.edit.tree.TreeModification)12 FixReplacement (com.google.gerrit.reviewdb.client.FixReplacement)11 Range (com.google.gerrit.reviewdb.client.Comment.Range)10 Test (org.junit.Test)10 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 ProjectState (com.google.gerrit.server.project.ProjectState)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Repository (org.eclipse.jgit.lib.Repository)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 RawInputUtil (com.google.gerrit.common.RawInputUtil)1 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 Comment (com.google.gerrit.reviewdb.client.Comment)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 Project (com.google.gerrit.reviewdb.client.Project)1 FileContentUtil (com.google.gerrit.server.change.FileContentUtil)1 ChangeEdit (com.google.gerrit.server.edit.ChangeEdit)1 ChangeFileContentModification (com.google.gerrit.server.edit.tree.ChangeFileContentModification)1 InvalidChangeOperationException (com.google.gerrit.server.project.InvalidChangeOperationException)1 Inject (com.google.inject.Inject)1