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");
}
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");
}
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");
}
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");
}
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");
}
Aggregations