Search in sources :

Example 6 with FixReplacement

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

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

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

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

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

the class FixReplacementInterpreterTest method replacementsMustNotReferToNegativeOffset.

@Test
public void replacementsMustNotReferToNegativeOffset() throws Exception {
    FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(1, -1, 1, 5), "modified");
    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)

Aggregations

FixReplacement (com.google.gerrit.reviewdb.client.FixReplacement)16 Range (com.google.gerrit.reviewdb.client.Comment.Range)13 Test (org.junit.Test)13 TreeModification (com.google.gerrit.server.edit.tree.TreeModification)9 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)3 Comment (com.google.gerrit.reviewdb.client.Comment)3 ArrayList (java.util.ArrayList)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 AutoValue (com.google.auto.value.AutoValue)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Strings (com.google.common.base.Strings)1 ListMultimap (com.google.common.collect.ListMultimap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Ordering (com.google.common.collect.Ordering)1 HashCode (com.google.common.hash.HashCode)1 Hashing (com.google.common.hash.Hashing)1 Nullable (com.google.gerrit.common.Nullable)1 RawInputUtil (com.google.gerrit.common.RawInputUtil)1