1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.diff.display.internal; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.ArrayUtils; |
28 |
|
import org.junit.Assert; |
29 |
|
import org.junit.Rule; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.diff.DiffManager; |
32 |
|
import org.xwiki.diff.DiffResult; |
33 |
|
import org.xwiki.diff.display.InlineDiffChunk; |
34 |
|
import org.xwiki.diff.display.InlineDiffChunk.Type; |
35 |
|
import org.xwiki.diff.display.InlineDiffDisplayer; |
36 |
|
import org.xwiki.diff.internal.DefaultDiffManager; |
37 |
|
import org.xwiki.test.ComponentManagerRule; |
38 |
|
import org.xwiki.test.annotation.ComponentList; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@ComponentList({ |
47 |
|
DefaultDiffManager.class, |
48 |
|
DefaultInlineDiffDisplayer.class |
49 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 13 |
Complexity Density: 0.5 |
|
50 |
|
public class DefaultInlineDiffDisplayerTest |
51 |
|
{ |
52 |
|
@Rule |
53 |
|
public final ComponentManagerRule componentManager = new ComponentManagerRule(); |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
55 |
1 |
@Test... |
56 |
|
public void testBothEmpty() throws Exception |
57 |
|
{ |
58 |
1 |
execute("", "", ""); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void testNoChange() throws Exception |
63 |
|
{ |
64 |
1 |
execute("xwiki", "xwiki", "xwiki"); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
public void testOriginalEmpty() throws Exception |
69 |
|
{ |
70 |
1 |
execute("", "xwiki", "+xwiki+"); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void testRevisedEmpty() throws Exception |
75 |
|
{ |
76 |
1 |
execute("xwiki", "", "-xwiki-"); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
public void testAddCharacter() throws Exception |
81 |
|
{ |
82 |
1 |
execute("xwki", "xwiki", "xw+i+ki"); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void testRemoveCharacter() throws Exception |
87 |
|
{ |
88 |
1 |
execute("xwiki", "xwki", "xw-i-ki"); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void testChangeCharacter() throws Exception |
93 |
|
{ |
94 |
1 |
execute("xwiki", "xwIki", "xw-i-+I+ki"); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
public void testEndPoints() throws Exception |
99 |
|
{ |
100 |
1 |
execute("wiki", "xwik", "+x+wik-i-"); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
public void testAddWord() throws Exception |
105 |
|
{ |
106 |
1 |
execute("123abc", "123XYZabc", "123+XYZ+abc"); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
109 |
1 |
@Test... |
110 |
|
public void testRemoveWord() throws Exception |
111 |
|
{ |
112 |
1 |
execute("123xyzABC", "123ABC", "123-xyz-ABC"); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
115 |
1 |
@Test... |
116 |
|
public void testChangeWord() throws Exception |
117 |
|
{ |
118 |
1 |
execute("123 xyz abc", "123 XYZ abc", "123 -xyz-+XYZ+ abc"); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void testChangeWords() throws Exception |
123 |
|
{ |
124 |
1 |
execute("123 456 789", "abc 456 xyz", "-123-+abc+ 456 -789-+xyz+"); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
@param |
132 |
|
@param |
133 |
|
@throws |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
135 |
12 |
private void execute(String previous, String next, String expected) throws Exception... |
136 |
|
{ |
137 |
12 |
List<Character> previousChars = Arrays.asList(ArrayUtils.toObject(previous.toCharArray())); |
138 |
12 |
List<Character> nextChars = Arrays.asList(ArrayUtils.toObject(next.toCharArray())); |
139 |
|
|
140 |
12 |
DiffManager diffManager = this.componentManager.getInstance(DiffManager.class); |
141 |
12 |
DiffResult<Character> diffResult = diffManager.diff(previousChars, nextChars, null); |
142 |
|
|
143 |
12 |
Map<Type, String> separators = new HashMap<Type, String>(); |
144 |
12 |
separators.put(Type.ADDED, "+"); |
145 |
12 |
separators.put(Type.DELETED, "-"); |
146 |
12 |
separators.put(Type.UNMODIFIED, ""); |
147 |
|
|
148 |
12 |
StringBuilder actual = new StringBuilder(); |
149 |
12 |
InlineDiffDisplayer inlineDiffDisplayer = this.componentManager.getInstance(InlineDiffDisplayer.class); |
150 |
12 |
for (InlineDiffChunk<Character> chunk : inlineDiffDisplayer.display(diffResult)) { |
151 |
31 |
String separator = separators.get(chunk.getType()); |
152 |
31 |
actual.append(separator).append(chunk).append(separator); |
153 |
|
} |
154 |
|
|
155 |
12 |
Assert.assertEquals(expected, actual.toString()); |
156 |
|
} |
157 |
|
} |