1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.diff.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.StringUtils; |
28 |
|
import org.junit.Assert; |
29 |
|
import org.junit.Rule; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.diff.Delta.Type; |
32 |
|
import org.xwiki.diff.DiffManager; |
33 |
|
import org.xwiki.diff.DiffResult; |
34 |
|
import org.xwiki.diff.MergeResult; |
35 |
|
import org.xwiki.logging.LogLevel; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
37 |
|
|
|
|
| 98.4% |
Uncovered Elements: 2 (124) |
Complexity: 9 |
Complexity Density: 0.08 |
|
38 |
|
public class DefaultDiffManagerTest |
39 |
|
{ |
40 |
|
@Rule |
41 |
|
public final MockitoComponentMockingRule<DiffManager> mocker = new MockitoComponentMockingRule<DiffManager>( |
42 |
|
DefaultDiffManager.class); |
43 |
|
|
44 |
|
|
45 |
|
@param |
46 |
|
@return |
47 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
48 |
87 |
private static List<Character> toCharacters(String str)... |
49 |
|
{ |
50 |
87 |
List<Character> characters; |
51 |
|
|
52 |
87 |
if (str != null) { |
53 |
87 |
characters = new ArrayList<Character>(str.length()); |
54 |
|
|
55 |
87 |
for (char c : str.toCharArray()) { |
56 |
323 |
characters.add(c); |
57 |
|
} |
58 |
|
} else { |
59 |
0 |
characters = Collections.emptyList(); |
60 |
|
} |
61 |
|
|
62 |
87 |
return characters; |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
5 |
private static String toString(List<Character> characters)... |
66 |
|
{ |
67 |
5 |
return StringUtils.join(characters, null); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void testDiffStringList() throws Exception |
74 |
|
{ |
75 |
|
|
76 |
|
|
77 |
1 |
DiffResult<String> result = this.mocker.getComponentUnderTest().diff(null, null, null); |
78 |
|
|
79 |
1 |
Assert.assertTrue(result.getPatch().isEmpty()); |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
1 |
result = this.mocker.getComponentUnderTest().diff(Collections.<String>emptyList(), |
84 |
|
Collections.<String>emptyList(), null); |
85 |
|
|
86 |
1 |
Assert.assertTrue(result.getPatch().isEmpty()); |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
1 |
result = this.mocker.getComponentUnderTest().diff(Arrays.asList("equals"), Arrays.asList("equals"), null); |
91 |
|
|
92 |
1 |
Assert.assertTrue(result.getPatch().isEmpty()); |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
1 |
result = this.mocker.getComponentUnderTest().diff(Collections.<String>emptyList(), Arrays.asList("next"), null); |
97 |
|
|
98 |
1 |
Assert.assertEquals(1, result.getPatch().size()); |
99 |
1 |
Assert.assertEquals(Type.INSERT, result.getPatch().get(0).getType()); |
100 |
1 |
Assert.assertEquals(Arrays.asList("next"), result.getPatch().get(0).getNext().getElements()); |
101 |
1 |
Assert.assertEquals(0, result.getPatch().get(0).getNext().getIndex()); |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
1 |
result = |
106 |
|
this.mocker.getComponentUnderTest().diff(Arrays.asList("previous"), Collections.<String>emptyList(), null); |
107 |
|
|
108 |
1 |
Assert.assertEquals(1, result.getPatch().size()); |
109 |
1 |
Assert.assertEquals(Type.DELETE, result.getPatch().get(0).getType()); |
110 |
1 |
Assert.assertEquals(Arrays.asList("previous"), result.getPatch().get(0).getPrevious().getElements()); |
111 |
1 |
Assert.assertEquals(0, result.getPatch().get(0).getPrevious().getIndex()); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
public void testDiffCharList() throws Exception |
116 |
|
{ |
117 |
|
|
118 |
|
|
119 |
1 |
DiffResult<Character> result = |
120 |
|
this.mocker.getComponentUnderTest().diff(Arrays.asList('a'), Arrays.asList('a'), null); |
121 |
|
|
122 |
1 |
Assert.assertTrue(result.getPatch().isEmpty()); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
1 |
result = this.mocker.getComponentUnderTest().diff(Arrays.asList('a'), Arrays.asList('b'), null); |
127 |
|
|
128 |
1 |
Assert.assertEquals(1, result.getPatch().size()); |
129 |
1 |
Assert.assertEquals(Type.CHANGE, result.getPatch().get(0).getType()); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
132 |
1 |
@Test... |
133 |
|
public void testMergeStringList() throws Exception |
134 |
|
{ |
135 |
1 |
MergeResult<String> result; |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
1 |
result = this.mocker.getComponentUnderTest().merge( |
140 |
|
Arrays.asList("some content"), Arrays.asList("some new content"), Arrays.asList("some content"), null); |
141 |
|
|
142 |
1 |
Assert.assertEquals(Arrays.asList("some new content"), result.getMerged()); |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
1 |
result = this.mocker.getComponentUnderTest().merge( |
147 |
|
Arrays.asList("some content"), Arrays.asList("some content"), Arrays.asList("some current content"), null); |
148 |
|
|
149 |
1 |
Assert.assertEquals(Arrays.asList("some current content"), result.getMerged()); |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
1 |
result = this.mocker.getComponentUnderTest().merge( |
154 |
|
Arrays.asList("some content"), Arrays.asList("some content", "after"), Arrays.asList("some content"), null); |
155 |
|
|
156 |
1 |
Assert.assertEquals(Arrays.asList("some content", "after"), result.getMerged()); |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
1 |
result = this.mocker.getComponentUnderTest().merge(Arrays.asList("some content"), |
161 |
|
Arrays.asList("before", "some content"), Arrays.asList("some content", "after"), null); |
162 |
|
|
163 |
1 |
Assert.assertEquals(Arrays.asList("before", "some content", "after"), result.getMerged()); |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
1 |
result = this.mocker.getComponentUnderTest().merge(Arrays.asList("some content"), |
168 |
|
Arrays.asList("some content", "after"), Arrays.asList("before", "some content"), null); |
169 |
|
|
170 |
1 |
Assert.assertEquals(Arrays.asList("before", "some content", "after"), result.getMerged()); |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
1 |
result = this.mocker.getComponentUnderTest().merge(Arrays.asList("some content"), |
175 |
|
Arrays.asList("some new content"), Arrays.asList("some new content"), null); |
176 |
|
|
177 |
1 |
Assert.assertEquals(Arrays.asList("some new content"), result.getMerged()); |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (52) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
180 |
1 |
@Test... |
181 |
|
public void testMergeCharList() throws Exception |
182 |
|
{ |
183 |
1 |
MergeResult<Character> result; |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
1 |
result = this.mocker.getComponentUnderTest() |
188 |
|
.merge(toCharacters("a"), toCharacters(""), toCharacters("b"), null); |
189 |
|
|
190 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
191 |
1 |
Assert.assertEquals(toCharacters("b"), result.getMerged()); |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
1 |
result = this.mocker.getComponentUnderTest() |
196 |
|
.merge(toCharacters("bc"), toCharacters("abc"), toCharacters("bc"), null); |
197 |
|
|
198 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
199 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
1 |
result = this.mocker.getComponentUnderTest() |
204 |
|
.merge(toCharacters("ab"), toCharacters("abc"), toCharacters("ab"), null); |
205 |
|
|
206 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
207 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
1 |
result = this.mocker.getComponentUnderTest() |
212 |
|
.merge(toCharacters("ac"), toCharacters("abc"), toCharacters("ac"), null); |
213 |
|
|
214 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
215 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
1 |
result = |
220 |
|
this.mocker.getComponentUnderTest().merge(toCharacters("b"), toCharacters("ab"), toCharacters("bc"), null); |
221 |
|
|
222 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
223 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
224 |
|
|
225 |
|
|
226 |
|
|
227 |
1 |
result = |
228 |
|
this.mocker.getComponentUnderTest().merge(toCharacters("b"), toCharacters("bc"), toCharacters("ab"), null); |
229 |
|
|
230 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
231 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
1 |
result = this.mocker.getComponentUnderTest() |
236 |
|
.merge(toCharacters("abc"), toCharacters("aibc"), toCharacters("abcj"), null); |
237 |
|
|
238 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
239 |
1 |
Assert.assertEquals(toCharacters("aibcj"), result.getMerged()); |
240 |
|
|
241 |
1 |
result = this.mocker.getComponentUnderTest() |
242 |
|
.merge(toCharacters("abc"), toCharacters("abcj"), toCharacters("aibc"), null); |
243 |
|
|
244 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
245 |
1 |
Assert.assertEquals(toCharacters("aibcj"), result.getMerged()); |
246 |
|
|
247 |
1 |
result = this.mocker.getComponentUnderTest() |
248 |
|
.merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), null); |
249 |
|
|
250 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
251 |
1 |
Assert.assertEquals(toCharacters("ajibc"), result.getMerged()); |
252 |
|
|
253 |
1 |
result = this.mocker.getComponentUnderTest() |
254 |
|
.merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), null); |
255 |
|
|
256 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
257 |
1 |
Assert.assertEquals(toCharacters("aijb"), result.getMerged()); |
258 |
|
|
259 |
1 |
result = this.mocker.getComponentUnderTest() |
260 |
|
.merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), null); |
261 |
|
|
262 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
263 |
1 |
Assert.assertEquals(toCharacters("aijb"), result.getMerged()); |
264 |
|
|
265 |
1 |
result = |
266 |
|
this.mocker.getComponentUnderTest().merge(toCharacters(""), toCharacters("ab"), toCharacters("abc"), null); |
267 |
|
|
268 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
269 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
270 |
|
|
271 |
1 |
result = |
272 |
|
this.mocker.getComponentUnderTest().merge(toCharacters(""), toCharacters("abc"), toCharacters("ab"), null); |
273 |
|
|
274 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
275 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
276 |
|
|
277 |
1 |
result = |
278 |
|
this.mocker.getComponentUnderTest().merge(toCharacters(""), toCharacters("bc"), toCharacters("abc"), null); |
279 |
|
|
280 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
281 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
282 |
|
|
283 |
1 |
result = |
284 |
|
this.mocker.getComponentUnderTest().merge(toCharacters(""), toCharacters("abc"), toCharacters("bc"), null); |
285 |
|
|
286 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
287 |
1 |
Assert.assertEquals(toCharacters("abc"), result.getMerged()); |
288 |
|
|
289 |
|
|
290 |
|
|
291 |
1 |
result = this.mocker.getComponentUnderTest().merge(toCharacters("Alice Macro"), |
292 |
|
toCharacters("Alice Wiki Macro (upgraded)"), toCharacters("Alice Extension"), null); |
293 |
|
|
294 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
295 |
1 |
Assert.assertEquals(toCharacters("Alice Wiki Extension (upgraded)"), result.getMerged()); |
296 |
|
|
297 |
1 |
result = this.mocker.getComponentUnderTest() |
298 |
|
.merge(toCharacters("$a(b)"), toCharacters("$c(d)e"), toCharacters("$c(d)e"), null); |
299 |
|
|
300 |
1 |
Assert.assertEquals(0, result.getLog().getLogs(LogLevel.ERROR).size()); |
301 |
1 |
Assert.assertEquals("$c(d)e", toString(result.getMerged())); |
302 |
|
} |
303 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
304 |
1 |
@Test... |
305 |
|
public void testMergeCharOnConflicts() throws Exception |
306 |
|
{ |
307 |
1 |
MergeResult<Character> result; |
308 |
|
|
309 |
|
|
310 |
1 |
result = |
311 |
|
this.mocker.getComponentUnderTest().merge(toCharacters("a"), toCharacters("b"), toCharacters("c"), null); |
312 |
|
|
313 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
314 |
1 |
Assert.assertEquals(toCharacters("c"), result.getMerged()); |
315 |
|
|
316 |
|
|
317 |
1 |
result = this.mocker.getComponentUnderTest() |
318 |
|
.merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), null); |
319 |
|
|
320 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
321 |
1 |
Assert.assertEquals("yycd", toString(result.getMerged())); |
322 |
|
|
323 |
|
|
324 |
1 |
result = this.mocker.getComponentUnderTest() |
325 |
|
.merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), null); |
326 |
|
|
327 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
328 |
1 |
Assert.assertEquals("yycd", toString(result.getMerged())); |
329 |
|
|
330 |
|
|
331 |
1 |
result = this.mocker.getComponentUnderTest() |
332 |
|
.merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), null); |
333 |
|
|
334 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
335 |
1 |
Assert.assertEquals("ddddcc", toString(result.getMerged())); |
336 |
|
|
337 |
|
|
338 |
1 |
result = this.mocker.getComponentUnderTest() |
339 |
|
.merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), null); |
340 |
|
|
341 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
342 |
1 |
Assert.assertEquals("ddddcc", toString(result.getMerged())); |
343 |
|
} |
344 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
345 |
1 |
@Test... |
346 |
|
public void testMergeWithEmptyNew() throws Exception |
347 |
|
{ |
348 |
1 |
MergeResult<Character> result; |
349 |
|
|
350 |
1 |
result = |
351 |
|
this.mocker.getComponentUnderTest().merge(toCharacters("a"), toCharacters(""), toCharacters("b"), null); |
352 |
|
|
353 |
1 |
Assert.assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); |
354 |
1 |
Assert.assertEquals(toCharacters("b"), result.getMerged()); |
355 |
|
} |
356 |
|
} |