Search in sources :

Example 6 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range 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 7 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range in project gerrit by GerritCodeReview.

the class FixReplacementInterpreterTest method replacementsMustNotReferToZeroLine.

@Test
public void replacementsMustNotReferToZeroLine() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(0, 0, 0, 0), "A new line\n");
    mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
    replay(fileContentUtil);
    expectedException.expect(ResourceConflictException.class);
    toTreeModifications(fixReplacement);
}
Also used : FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) Range(com.google.gerrit.reviewdb.client.Comment.Range) Test(org.junit.Test)

Example 8 with Range

use of com.google.gerrit.reviewdb.client.Comment.Range 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 Range

use of com.google.gerrit.reviewdb.client.Comment.Range 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 Range

use of com.google.gerrit.reviewdb.client.Comment.Range 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

Range (com.google.gerrit.reviewdb.client.Comment.Range)15 FixReplacement (com.google.gerrit.reviewdb.client.FixReplacement)15 Test (org.junit.Test)15 TreeModification (com.google.gerrit.server.edit.tree.TreeModification)10