use of com.google.gerrit.server.patch.IntraLineDiffKey in project gerrit by GerritCodeReview.
the class PatchListCacheIT method harmfulMutationsOfEditsAreNotPossibleForIntraLineDiffArgsAndCachedValue.
@Test
public void harmfulMutationsOfEditsAreNotPossibleForIntraLineDiffArgsAndCachedValue() throws Exception {
String a = "First line\nSecond line\n";
String b = "1st line\n2nd line\n";
Text aText = new Text(a.getBytes(UTF_8));
Text bText = new Text(b.getBytes(UTF_8));
Edit inputEdit = new Edit(0, 2, 0, 2);
List<Edit> inputEdits = new ArrayList<>(ImmutableList.of(inputEdit));
IntraLineDiffKey diffKey = IntraLineDiffKey.create(ObjectId.zeroId(), ObjectId.zeroId(), Whitespace.IGNORE_NONE);
IntraLineDiffArgs diffArgs = IntraLineDiffArgs.create(aText, bText, inputEdits, project, ObjectId.zeroId(), "file.txt");
IntraLineDiff intraLineDiff = patchListCache.getIntraLineDiff(diffKey, diffArgs);
Edit outputEdit = Iterables.getOnlyElement(intraLineDiff.getEdits());
outputEdit.shift(5);
inputEdit.shift(7);
inputEdits.add(new Edit(43, 47, 50, 51));
Edit originalEdit = new Edit(0, 2, 0, 2);
assertThat(diffArgs.edits()).containsExactly(originalEdit);
assertThat(intraLineDiff.getEdits()).containsExactly(originalEdit);
}
Aggregations