Search in sources :

Example 6 with TreeModification

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

the class FixReplacementInterpreterTest method replacementsDoNotNeedToBeOrderedAccordingToRange.

@Test
public void replacementsDoNotNeedToBeOrderedAccordingToRange() throws Exception {
    FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 0, 2, 0), "1st modification\n");
    FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(3, 0, 4, 0), "2nd modification\n");
    FixReplacement fixReplacement3 = new FixReplacement(filePath1, new Range(4, 0, 5, 0), "3rd modification\n");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\nFourth line\nFifth line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement2, fixReplacement1, fixReplacement3);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("1st modification\nSecond line\n2nd modification\n3rd modification\nFifth 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 7 with TreeModification

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

the class FixReplacementInterpreterTest method replacementsCanAddContentAtEndOfFile.

@Test
public void replacementsCanAddContentAtEndOfFile() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(4, 0, 4, 0), "New content");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First line\nSecond line\nThird line\nNew content");
}
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 8 with TreeModification

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

the class FixReplacementInterpreterTest method replacementsCanAddALine.

@Test
public void replacementsCanAddALine() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(2, 0, 2, 0), "A new line\n");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First line\nA new line\nSecond 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 9 with TreeModification

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

the class FixReplacementInterpreterTest method replacementsMaySpanMultipleLines.

@Test
public void replacementsMaySpanMultipleLines() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(1, 6, 3, 1), "and t");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement);
    assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First and third 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 10 with TreeModification

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

the class FixReplacementInterpreterTest method replacementsCanModifySeveralFilesInAnyOrder.

@Test
public void replacementsCanModifySeveralFilesInAnyOrder() throws Exception {
    FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 1, 3, 2), "Modified content");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    FixReplacement fixReplacement2 = new FixReplacement(filePath2, new Range(2, 0, 3, 0), "First modification\n");
    FixReplacement fixReplacement3 = new FixReplacement(filePath2, new Range(3, 0, 4, 0), "Second modification\n");
    mockFileContent(filePath2, "1st line\n2nd line\n3rd line\n");
    replay(fileContentUtil);
    List<TreeModification> treeModifications = toTreeModifications(fixReplacement3, fixReplacement1, fixReplacement2);
    List<TreeModification> sortedTreeModifications = getSortedCopy(treeModifications);
    assertThatList(sortedTreeModifications).element(0).asChangeFileContentModification().newContent().isEqualTo("FModified contentird line\n");
    assertThatList(sortedTreeModifications).element(1).asChangeFileContentModification().newContent().isEqualTo("1st line\nFirst modification\nSecond modification\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