1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.annotation.maintainer; |
21 |
|
|
22 |
|
import static org.junit.Assert.assertEquals; |
23 |
|
import static org.junit.Assert.assertNotNull; |
24 |
|
import static org.junit.Assert.assertTrue; |
25 |
|
|
26 |
|
import java.io.IOException; |
27 |
|
import java.util.ArrayList; |
28 |
|
import java.util.Collection; |
29 |
|
import java.util.List; |
30 |
|
|
31 |
|
import org.junit.Test; |
32 |
|
import org.junit.runner.RunWith; |
33 |
|
import org.junit.runners.Parameterized; |
34 |
|
import org.junit.runners.Parameterized.Parameters; |
35 |
|
import org.xwiki.annotation.Annotation; |
36 |
|
import org.xwiki.annotation.AnnotationsMockSetup; |
37 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@RunWith(Parameterized.class) |
|
|
| 97.8% |
Uncovered Elements: 2 (93) |
Complexity: 12 |
Complexity Density: 0.15 |
|
46 |
|
public class AnnotationMaintainerTest extends AbstractComponentTestCase |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static Collection<String[]> files = new ArrayList<String[]>(); |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
protected String docName; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
protected AnnotationMaintainer annotationMaintainer; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
protected AnnotationsMockSetup setup; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (49) |
Complexity: 1 |
Complexity Density: 0.02 |
|
68 |
1 |
static {... |
69 |
1 |
addFileToTest("maintainer/correction/Correction1"); |
70 |
1 |
addFileToTest("maintainer/correction/Correction2"); |
71 |
1 |
addFileToTest("maintainer/correction/Correction3"); |
72 |
1 |
addFileToTest("maintainer/correction/Correction4"); |
73 |
|
|
74 |
1 |
addFileToTest("maintainer/correction/multiple/CorrectionMultiple1"); |
75 |
1 |
addFileToTest("maintainer/correction/multiple/CorrectionMultiple2"); |
76 |
1 |
addFileToTest("maintainer/correction/multiple/CorrectionMultiple3"); |
77 |
1 |
addFileToTest("maintainer/correction/multiple/CorrectionMultiple4"); |
78 |
1 |
addFileToTest("maintainer/correction/multiple/CorrectionMultiple5"); |
79 |
|
|
80 |
1 |
addFileToTest("maintainer/endpoint/Beginning1"); |
81 |
1 |
addFileToTest("maintainer/endpoint/Beginning2"); |
82 |
1 |
addFileToTest("maintainer/endpoint/Beginning3"); |
83 |
1 |
addFileToTest("maintainer/endpoint/Beginning4"); |
84 |
1 |
addFileToTest("maintainer/endpoint/Beginning5"); |
85 |
|
|
86 |
1 |
addFileToTest("maintainer/endpoint/End1"); |
87 |
1 |
addFileToTest("maintainer/endpoint/End2"); |
88 |
1 |
addFileToTest("maintainer/endpoint/End3"); |
89 |
1 |
addFileToTest("maintainer/endpoint/End4"); |
90 |
1 |
addFileToTest("maintainer/endpoint/End5"); |
91 |
|
|
92 |
1 |
addFileToTest("maintainer/endpoint/Endpoints1"); |
93 |
1 |
addFileToTest("maintainer/endpoint/Endpoints2"); |
94 |
1 |
addFileToTest("maintainer/endpoint/Endpoints3"); |
95 |
1 |
addFileToTest("maintainer/endpoint/Endpoints4"); |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
1 |
addFileToTest("maintainer/paragraph/Paragraph1"); |
101 |
1 |
addFileToTest("maintainer/alter/Altered1"); |
102 |
|
|
103 |
|
|
104 |
1 |
addFileToTest("maintainer/alter/Altered3"); |
105 |
1 |
addFileToTest("maintainer/alter/Altered4"); |
106 |
|
|
107 |
|
|
108 |
1 |
addFileToTest("maintainer/uniqueness/Unique1"); |
109 |
1 |
addFileToTest("maintainer/uniqueness/Unique2"); |
110 |
1 |
addFileToTest("maintainer/uniqueness/Unique3"); |
111 |
|
|
112 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate1"); |
113 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate2"); |
114 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate3"); |
115 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate4"); |
116 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate5"); |
117 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate6"); |
118 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate7"); |
119 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate8"); |
120 |
1 |
addFileToTest("maintainer/uniqueness/Duplicate9"); |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
addFileToTest("maintainer/unchanged/Unchanged1"); |
125 |
1 |
addFileToTest("maintainer/unchanged/Unchanged2"); |
126 |
1 |
addFileToTest("maintainer/unchanged/Unchanged3"); |
127 |
1 |
addFileToTest("maintainer/unchanged/Unchanged4"); |
128 |
1 |
addFileToTest("maintainer/unchanged/Unchanged5"); |
129 |
|
|
130 |
1 |
addFileToTest("maintainer/spaces/Spaces1"); |
131 |
1 |
addFileToTest("maintainer/spaces/Spaces2"); |
132 |
1 |
addFileToTest("maintainer/spaces/Spaces3"); |
133 |
1 |
addFileToTest("maintainer/spaces/Spaces4"); |
134 |
1 |
addFileToTest("maintainer/spaces/Spaces5"); |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
@param |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
49 |
public AnnotationMaintainerTest(String docName)... |
148 |
|
{ |
149 |
49 |
this.docName = docName; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
49 |
protected static void addFileToTest(String docName)... |
158 |
|
{ |
159 |
49 |
files.add(new String[] {docName}); |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
@return |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
1 |
@Parameters... |
166 |
|
public static Collection<String[]> data() |
167 |
|
{ |
168 |
1 |
return files; |
169 |
|
} |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
171 |
49 |
@Override... |
172 |
|
public void setUp() throws Exception |
173 |
|
{ |
174 |
49 |
super.setUp(); |
175 |
|
|
176 |
49 |
annotationMaintainer = getComponentManager().getInstance(AnnotationMaintainer.class); |
177 |
|
} |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
179 |
49 |
@Override... |
180 |
|
protected void registerComponents() throws Exception |
181 |
|
{ |
182 |
49 |
super.registerComponents(); |
183 |
|
|
184 |
|
|
185 |
49 |
setup = new AnnotationsMockSetup(getComponentManager(), new TestDocumentFactory()); |
186 |
49 |
setup.setupExpectations(docName); |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
@throws |
193 |
|
@throws |
194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
195 |
49 |
@Test... |
196 |
|
public void testUpdate() throws IOException, MaintainerServiceException |
197 |
|
{ |
198 |
|
|
199 |
49 |
MockDocument doc = ((TestDocumentFactory) setup.getDocFactory()).getDocument(docName); |
200 |
|
|
201 |
49 |
copyOriginalSelections(doc); |
202 |
|
|
203 |
49 |
annotationMaintainer.updateAnnotations(docName, doc.getSource(), doc.getModifiedSource()); |
204 |
|
|
205 |
|
|
206 |
49 |
assertSameAnnotations(doc.getUpdatedAnnotations(), doc.getAnnotations()); |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@param |
213 |
|
@param |
214 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
215 |
49 |
private void assertSameAnnotations(List<Annotation> expected, List<Annotation> actual)... |
216 |
|
{ |
217 |
49 |
assertTrue(expected.size() == actual.size()); |
218 |
|
|
219 |
49 |
for (Annotation actualAnn : actual) { |
220 |
49 |
Annotation expectedAnn = getAnnotation(actualAnn.getId(), expected); |
221 |
49 |
assertNotNull(expectedAnn); |
222 |
49 |
assertEquals(expectedAnn.getSelection(), actualAnn.getSelection()); |
223 |
49 |
assertEquals(expectedAnn.getSelectionLeftContext(), actualAnn.getSelectionLeftContext()); |
224 |
49 |
assertEquals(expectedAnn.getSelectionRightContext(), actualAnn.getSelectionRightContext()); |
225 |
49 |
assertEquals(expectedAnn.getState(), actualAnn.getState()); |
226 |
49 |
assertEquals(expectedAnn.getOriginalSelection(), actualAnn.getOriginalSelection()); |
227 |
|
} |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@param |
234 |
|
@param |
235 |
|
@return |
236 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
237 |
77 |
private Annotation getAnnotation(String annId, Collection<Annotation> list)... |
238 |
|
{ |
239 |
77 |
for (Annotation ann : list) { |
240 |
77 |
if (ann.getId().equals(annId)) { |
241 |
77 |
return ann; |
242 |
|
} |
243 |
|
} |
244 |
|
|
245 |
0 |
return null; |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
@param |
253 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
254 |
49 |
private void copyOriginalSelections(MockDocument doc)... |
255 |
|
{ |
256 |
|
|
257 |
49 |
for (Annotation updatedAnn : doc.getUpdatedAnnotations()) { |
258 |
49 |
if (updatedAnn.getState() != AnnotationState.UPDATED) { |
259 |
21 |
continue; |
260 |
|
} |
261 |
28 |
Annotation originalAnn = getAnnotation(updatedAnn.getId(), doc.getAnnotations()); |
262 |
28 |
updatedAnn.setOriginalSelection(originalAnn.getSelection()); |
263 |
|
} |
264 |
|
} |
265 |
|
} |