|
14 | 14 | importorg.junit.jupiter.api.Test;
|
15 | 15 |
|
16 | 16 | importcom.github.difflib.DiffUtils;
|
| 17 | +importjava.util.ArrayList; |
17 | 18 |
|
18 | 19 | publicclassPatchTest {
|
19 | 20 |
|
@@ -78,4 +79,48 @@ public void testPatch_Serializable() throws IOException, ClassNotFoundException
|
78 | 79 | }
|
79 | 80 |
|
80 | 81 | }
|
| 82 | + |
| 83 | +@Test |
| 84 | +publicvoidtestPatch_Change_withExceptionProcessor() { |
| 85 | +finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd"); |
| 86 | +finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd"); |
| 87 | + |
| 88 | +finalPatch<String>patch =DiffUtils.diff(changeTest_from,changeTest_to); |
| 89 | + |
| 90 | +changeTest_from.set(2,"CDC"); |
| 91 | + |
| 92 | +patch.withConflictOutput(newConflictOutput<String>() { |
| 93 | +@Override |
| 94 | +publicvoidprocessConflict(VerifyChunkverifyChunk,AbstractDelta<String>delta,List<String>result)throwsPatchFailedException { |
| 95 | +if (result.size() >delta.getSource().getPosition()) { |
| 96 | +List<String>orgData =newArrayList<>(); |
| 97 | + |
| 98 | +for (inti =0;i <delta.getSource().size();i++) { |
| 99 | +orgData.add(result.get(delta.getSource().getPosition())); |
| 100 | +result.remove(delta.getSource().getPosition()); |
| 101 | + } |
| 102 | + |
| 103 | +orgData.add(0,"<<<<<< HEAD"); |
| 104 | +orgData.add("======"); |
| 105 | +orgData.addAll(delta.getSource().getLines()); |
| 106 | +orgData.add(">>>>>>> PATCH"); |
| 107 | + |
| 108 | +result.addAll(delta.getSource().getPosition(),orgData); |
| 109 | + |
| 110 | + }else { |
| 111 | +thrownewUnsupportedOperationException("Not supported yet.");//To change body of generated methods, choose Tools | Templates. |
| 112 | + } |
| 113 | + } |
| 114 | + }); |
| 115 | + |
| 116 | +try { |
| 117 | +List<String>data =DiffUtils.patch(changeTest_from,patch); |
| 118 | +assertEquals(9,data.size()); |
| 119 | + |
| 120 | +assertEquals(Arrays.asList("aaa","<<<<<< HEAD","bbb","CDC","======","bbb","ccc",">>>>>>> PATCH","ddd"),data); |
| 121 | + |
| 122 | + }catch (PatchFailedExceptione) { |
| 123 | +fail(e.getMessage()); |
| 124 | + } |
| 125 | + } |
81 | 126 | }
|