1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.annotation; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.util.Collection; |
24 |
|
|
25 |
|
import org.hamcrest.Description; |
26 |
|
import org.jmock.Expectations; |
27 |
|
import org.jmock.Mockery; |
28 |
|
import org.jmock.api.Action; |
29 |
|
import org.jmock.api.Invocation; |
30 |
|
import org.jmock.integration.junit4.JUnit4Mockery; |
31 |
|
import org.xwiki.annotation.io.IOService; |
32 |
|
import org.xwiki.annotation.io.IOServiceException; |
33 |
|
import org.xwiki.annotation.io.IOTargetService; |
34 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
35 |
|
import org.xwiki.component.manager.ComponentManager; |
36 |
|
import org.xwiki.component.manager.ComponentRepositoryException; |
37 |
|
|
38 |
|
|
39 |
|
@link@link |
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 78.4% |
Uncovered Elements: 11 (51) |
Complexity: 12 |
Complexity Density: 0.32 |
|
45 |
|
public class AnnotationsMockSetup |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
protected Mockery mockery = new JUnit4Mockery(); |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
protected IOTargetService ioTargetService; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
protected IOService ioService; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
protected TestDocumentFactory docFactory; |
67 |
|
|
68 |
|
|
69 |
|
@link@link |
70 |
|
|
71 |
|
|
72 |
|
@param |
73 |
|
@param |
74 |
|
@throws |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
76 |
49 |
public AnnotationsMockSetup(ComponentManager componentManager, TestDocumentFactory docFactory)... |
77 |
|
throws ComponentRepositoryException |
78 |
|
{ |
79 |
|
|
80 |
49 |
ioTargetService = mockery.mock(IOTargetService.class); |
81 |
49 |
DefaultComponentDescriptor<IOTargetService> iotsDesc = new DefaultComponentDescriptor<IOTargetService>(); |
82 |
49 |
iotsDesc.setRole(IOTargetService.class); |
83 |
49 |
componentManager.registerComponent(iotsDesc, ioTargetService); |
84 |
|
|
85 |
|
|
86 |
49 |
ioService = mockery.mock(IOService.class); |
87 |
49 |
DefaultComponentDescriptor<IOService> ioDesc = new DefaultComponentDescriptor<IOService>(); |
88 |
49 |
ioDesc.setRole(IOService.class); |
89 |
49 |
componentManager.registerComponent(ioDesc, ioService); |
90 |
|
|
91 |
49 |
this.docFactory = docFactory; |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
@link@link |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@param |
100 |
|
@throws |
101 |
|
@throws |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
49 |
public void setupExpectations(final String docName) throws IOServiceException, IOException... |
104 |
|
{ |
105 |
49 |
mockery.checking(new Expectations() |
106 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
107 |
49 |
{... |
108 |
49 |
MockDocument mDoc = docFactory.getDocument(docName); |
109 |
|
|
110 |
49 |
allowing(ioService).getAnnotations(with(docName)); |
111 |
49 |
will(returnValue(mDoc.getAnnotations())); |
112 |
|
|
113 |
49 |
allowing(ioService).updateAnnotations(with(docName), with(any(Collection.class))); |
114 |
|
|
115 |
49 |
will(new Action() |
116 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
@Override... |
118 |
|
public void describeTo(Description description) |
119 |
|
{ |
120 |
0 |
description.appendText("Updates the annotations"); |
121 |
|
} |
122 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
123 |
49 |
@Override... |
124 |
|
public Object invoke(Invocation invocation) throws Throwable |
125 |
|
{ |
126 |
49 |
String documentName = (String) invocation.getParameter(0); |
127 |
49 |
MockDocument document = docFactory.getDocument(documentName); |
128 |
49 |
Collection<Annotation> annList = (Collection<Annotation>) invocation.getParameter(1); |
129 |
49 |
for (Annotation ann : annList) { |
130 |
35 |
Annotation toUpdate = getAnnotation(ann.getId(), document.getAnnotations()); |
131 |
|
|
132 |
35 |
if (toUpdate != null) { |
133 |
35 |
document.getAnnotations().remove(toUpdate); |
134 |
|
} |
135 |
35 |
document.getAnnotations().add(ann); |
136 |
|
} |
137 |
49 |
return null; |
138 |
|
} |
139 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
140 |
35 |
private Annotation getAnnotation(String annId, Collection<Annotation> list)... |
141 |
|
{ |
142 |
35 |
for (Annotation ann : list) { |
143 |
35 |
if (ann.getId().equals(annId)) { |
144 |
35 |
return ann; |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
0 |
return null; |
149 |
|
} |
150 |
|
}); |
151 |
|
|
152 |
49 |
allowing(ioTargetService).getSource(with(docName)); |
153 |
49 |
will(returnValue(mDoc.getSource())); |
154 |
|
|
155 |
49 |
allowing(ioTargetService).getSourceSyntax(with(docName)); |
156 |
49 |
will(returnValue(mDoc.getSyntax())); |
157 |
|
} |
158 |
|
}); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
@return |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
0 |
public Mockery getMockery()... |
165 |
|
{ |
166 |
0 |
return mockery; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
public IOTargetService getIoTargetService()... |
173 |
|
{ |
174 |
0 |
return ioTargetService; |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
@return |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
public IOService getIoService()... |
181 |
|
{ |
182 |
0 |
return ioService; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
@return |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
49 |
public TestDocumentFactory getDocFactory()... |
189 |
|
{ |
190 |
49 |
return docFactory; |
191 |
|
} |
192 |
|
} |