1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.icon.internal; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.icon.Icon; |
29 |
|
import org.xwiki.icon.IconException; |
30 |
|
import org.xwiki.icon.IconSet; |
31 |
|
import org.xwiki.skinx.SkinExtension; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
|
34 |
|
import static org.junit.Assert.assertEquals; |
35 |
|
import static org.junit.Assert.assertNotNull; |
36 |
|
import static org.mockito.ArgumentMatchers.any; |
37 |
|
import static org.mockito.ArgumentMatchers.eq; |
38 |
|
import static org.mockito.Mockito.never; |
39 |
|
import static org.mockito.Mockito.verify; |
40 |
|
import static org.mockito.Mockito.when; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@since |
46 |
|
@version |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (92) |
Complexity: 12 |
Complexity Density: 0.15 |
|
48 |
|
public class DefaultIconRendererTest |
49 |
|
{ |
50 |
|
@Rule |
51 |
|
public MockitoComponentMockingRule<DefaultIconRenderer> mocker = |
52 |
|
new MockitoComponentMockingRule<>(DefaultIconRenderer.class); |
53 |
|
|
54 |
|
private SkinExtension skinExtension; |
55 |
|
|
56 |
|
private SkinExtension linkExtension; |
57 |
|
|
58 |
|
private SkinExtension jsExtension; |
59 |
|
|
60 |
|
private VelocityRenderer velocityRenderer; |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
62 |
10 |
@Before... |
63 |
|
public void setUp() throws Exception |
64 |
|
{ |
65 |
10 |
skinExtension = mocker.getInstance(SkinExtension.class, "ssx"); |
66 |
10 |
linkExtension = mocker.getInstance(SkinExtension.class, "linkx"); |
67 |
10 |
jsExtension = mocker.getInstance(SkinExtension.class, "jsx"); |
68 |
10 |
velocityRenderer = mocker.getInstance(VelocityRenderer.class); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void render() throws Exception |
73 |
|
{ |
74 |
1 |
IconSet iconSet = new IconSet("default"); |
75 |
1 |
iconSet.setRenderWiki("image:$icon.png"); |
76 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
77 |
1 |
when(velocityRenderer.render("#set($icon = \"blabla\")\nimage:$icon.png")).thenReturn("image:blabla.png"); |
78 |
|
|
79 |
|
|
80 |
1 |
String result = mocker.getComponentUnderTest().render("test", iconSet); |
81 |
|
|
82 |
|
|
83 |
1 |
assertEquals("image:blabla.png", result); |
84 |
1 |
verify(linkExtension, never()).use(any()); |
85 |
1 |
verify(skinExtension, never()).use(any()); |
86 |
1 |
verify(jsExtension, never()).use(any()); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
89 |
1 |
@Test... |
90 |
|
public void renderWithCSS() throws Exception |
91 |
|
{ |
92 |
1 |
IconSet iconSet = new IconSet("default"); |
93 |
1 |
iconSet.setCss("css"); |
94 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
95 |
1 |
when(velocityRenderer.render("css")).thenReturn("velocityParsedCSS"); |
96 |
|
|
97 |
|
|
98 |
1 |
mocker.getComponentUnderTest().render("test", iconSet); |
99 |
|
|
100 |
|
|
101 |
1 |
Map<String, Object> parameters = new HashMap(); |
102 |
1 |
parameters.put("rel", "stylesheet"); |
103 |
1 |
verify(linkExtension).use(eq("velocityParsedCSS"), eq(parameters)); |
104 |
1 |
verify(skinExtension, never()).use(any()); |
105 |
1 |
verify(jsExtension, never()).use(any()); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void renderWithSSX() throws Exception |
110 |
|
{ |
111 |
1 |
IconSet iconSet = new IconSet("default"); |
112 |
1 |
iconSet.setSsx("ssx"); |
113 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
114 |
|
|
115 |
|
|
116 |
1 |
mocker.getComponentUnderTest().render("test", iconSet); |
117 |
|
|
118 |
|
|
119 |
1 |
verify(skinExtension).use("ssx"); |
120 |
1 |
verify(linkExtension, never()).use(any()); |
121 |
1 |
verify(jsExtension, never()).use(any()); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void renderWithJSX() throws Exception |
126 |
|
{ |
127 |
1 |
IconSet iconSet = new IconSet("default"); |
128 |
1 |
iconSet.setJsx("jsx"); |
129 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
130 |
|
|
131 |
|
|
132 |
1 |
mocker.getComponentUnderTest().render("test", iconSet); |
133 |
|
|
134 |
|
|
135 |
1 |
verify(jsExtension).use("jsx"); |
136 |
1 |
verify(linkExtension, never()).use(any()); |
137 |
1 |
verify(skinExtension, never()).use(any()); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
140 |
1 |
@Test... |
141 |
|
public void renderHTML() throws Exception |
142 |
|
{ |
143 |
1 |
IconSet iconSet = new IconSet("default"); |
144 |
1 |
iconSet.setRenderHTML("<img src=\"$icon.png\" />"); |
145 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
146 |
|
|
147 |
1 |
when(velocityRenderer.render("#set($icon = \"blabla\")\n<img src=\"$icon.png\" />")) |
148 |
|
.thenReturn("<img src=\"blabla.png\" />"); |
149 |
|
|
150 |
|
|
151 |
1 |
String result = mocker.getComponentUnderTest().renderHTML("test", iconSet); |
152 |
|
|
153 |
|
|
154 |
1 |
assertEquals("<img src=\"blabla.png\" />", result); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void renderHTMLWithCSS() throws Exception |
159 |
|
{ |
160 |
1 |
IconSet iconSet = new IconSet("default"); |
161 |
1 |
iconSet.setCss("css"); |
162 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
163 |
1 |
when(velocityRenderer.render("css")).thenReturn("velocityParsedCSS"); |
164 |
|
|
165 |
|
|
166 |
1 |
mocker.getComponentUnderTest().renderHTML("test", iconSet); |
167 |
|
|
168 |
|
|
169 |
1 |
Map<String, Object> parameters = new HashMap(); |
170 |
1 |
parameters.put("rel", "stylesheet"); |
171 |
1 |
verify(linkExtension).use(eq("velocityParsedCSS"), eq(parameters)); |
172 |
1 |
verify(skinExtension, never()).use(any()); |
173 |
1 |
verify(jsExtension, never()).use(any()); |
174 |
|
} |
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
176 |
1 |
@Test... |
177 |
|
public void renderHTMLWithSSX() throws Exception |
178 |
|
{ |
179 |
1 |
IconSet iconSet = new IconSet("default"); |
180 |
1 |
iconSet.setSsx("ssx"); |
181 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
182 |
|
|
183 |
|
|
184 |
1 |
mocker.getComponentUnderTest().renderHTML("test", iconSet); |
185 |
|
|
186 |
|
|
187 |
1 |
verify(skinExtension).use("ssx"); |
188 |
1 |
verify(linkExtension, never()).use(any()); |
189 |
1 |
verify(jsExtension, never()).use(any()); |
190 |
|
} |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
192 |
1 |
@Test... |
193 |
|
public void renderHTMLWithJSX() throws Exception |
194 |
|
{ |
195 |
1 |
IconSet iconSet = new IconSet("default"); |
196 |
1 |
iconSet.setJsx("jsx"); |
197 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
198 |
|
|
199 |
|
|
200 |
1 |
mocker.getComponentUnderTest().renderHTML("test", iconSet); |
201 |
|
|
202 |
|
|
203 |
1 |
verify(jsExtension).use("jsx"); |
204 |
1 |
verify(linkExtension, never()).use(any()); |
205 |
1 |
verify(skinExtension, never()).use(any()); |
206 |
|
} |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
208 |
1 |
@Test... |
209 |
|
public void renderNonExistentIcon() throws Exception |
210 |
|
{ |
211 |
1 |
IconSet iconSet = new IconSet("default"); |
212 |
|
|
213 |
|
|
214 |
1 |
String result = mocker.getComponentUnderTest().render("non-existent-icon", iconSet); |
215 |
|
|
216 |
|
|
217 |
1 |
assertEquals("", result); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1PASS
|
|
220 |
1 |
@Test... |
221 |
|
public void renderWithException() throws Exception |
222 |
|
{ |
223 |
1 |
IconSet iconSet = new IconSet("default"); |
224 |
1 |
iconSet.setRenderWiki("image:$icon.png"); |
225 |
1 |
iconSet.addIcon("test", new Icon("blabla")); |
226 |
1 |
IconException exception = new IconException("exception", null); |
227 |
1 |
when(velocityRenderer.render(any())).thenThrow(exception); |
228 |
|
|
229 |
|
|
230 |
1 |
IconException caughtException = null; |
231 |
1 |
try { |
232 |
1 |
mocker.getComponentUnderTest().render("test", iconSet); |
233 |
|
} catch (IconException e) { |
234 |
1 |
caughtException = e; |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
1 |
assertNotNull(caughtException); |
239 |
1 |
assertEquals(exception, caughtException); |
240 |
|
} |
241 |
|
|
242 |
|
} |