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.List; |
23 |
|
|
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.icon.Icon; |
28 |
|
import org.xwiki.icon.IconRenderer; |
29 |
|
import org.xwiki.icon.IconSet; |
30 |
|
import org.xwiki.icon.IconSetManager; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
32 |
|
|
33 |
|
import static org.junit.Assert.assertEquals; |
34 |
|
import static org.junit.Assert.assertTrue; |
35 |
|
import static org.mockito.Mockito.when; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@since |
41 |
|
@version |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (80) |
Complexity: 7 |
Complexity Density: 0.1 |
|
43 |
|
public class DefaultIconManagerTest |
44 |
|
{ |
45 |
|
@Rule |
46 |
|
public MockitoComponentMockingRule<DefaultIconManager> mocker = |
47 |
|
new MockitoComponentMockingRule<>(DefaultIconManager.class); |
48 |
|
|
49 |
|
private IconSetManager iconSetManager; |
50 |
|
|
51 |
|
private IconRenderer iconRenderer; |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
53 |
6 |
@Before... |
54 |
|
public void setUp() throws Exception |
55 |
|
{ |
56 |
6 |
iconSetManager = mocker.getInstance(IconSetManager.class); |
57 |
6 |
iconRenderer = mocker.getInstance(IconRenderer.class); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void render() throws Exception |
62 |
|
{ |
63 |
1 |
IconSet iconSet = new IconSet("silk"); |
64 |
1 |
iconSet.addIcon("test", new Icon("hello")); |
65 |
1 |
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet); |
66 |
1 |
when(iconRenderer.render("test", iconSet)).thenReturn("rendered icon"); |
67 |
|
|
68 |
|
|
69 |
1 |
String result = mocker.getComponentUnderTest().render("test"); |
70 |
1 |
assertEquals("rendered icon", result); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void renderWithFallBack() throws Exception |
75 |
|
{ |
76 |
1 |
IconSet iconSet = new IconSet("silk"); |
77 |
1 |
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet); |
78 |
|
|
79 |
1 |
IconSet defaultIconSet = new IconSet("default"); |
80 |
1 |
when(iconSetManager.getDefaultIconSet()).thenReturn(defaultIconSet); |
81 |
1 |
when(iconRenderer.render("test", defaultIconSet)).thenReturn("rendered icon"); |
82 |
|
|
83 |
|
|
84 |
1 |
String result = mocker.getComponentUnderTest().render("test"); |
85 |
1 |
assertEquals("rendered icon", result); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void renderHTML() throws Exception |
90 |
|
{ |
91 |
1 |
IconSet iconSet = new IconSet("silk"); |
92 |
1 |
iconSet.addIcon("test", new Icon("hello")); |
93 |
1 |
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet); |
94 |
1 |
when(iconRenderer.renderHTML("test", iconSet)).thenReturn("rendered icon"); |
95 |
|
|
96 |
|
|
97 |
1 |
String result = mocker.getComponentUnderTest().renderHTML("test"); |
98 |
1 |
assertEquals("rendered icon", result); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void renderHTMLWithFallBack() throws Exception |
103 |
|
{ |
104 |
1 |
IconSet iconSet = new IconSet("silk"); |
105 |
1 |
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet); |
106 |
|
|
107 |
1 |
IconSet defaultIconSet = new IconSet("default"); |
108 |
1 |
when(iconSetManager.getDefaultIconSet()).thenReturn(defaultIconSet); |
109 |
1 |
when(iconRenderer.renderHTML("test", defaultIconSet)).thenReturn("rendered icon"); |
110 |
|
|
111 |
|
|
112 |
1 |
String result = mocker.getComponentUnderTest().renderHTML("test"); |
113 |
1 |
assertEquals("rendered icon", result); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
116 |
1 |
@Test... |
117 |
|
public void renderWithIconSetName() throws Exception |
118 |
|
{ |
119 |
|
|
120 |
1 |
IconSet iconSet1 = new IconSet("iconSet1"); |
121 |
1 |
iconSet1.addIcon("icon1", new Icon("icon")); |
122 |
1 |
when(iconSetManager.getIconSet("iconSet1")).thenReturn(iconSet1); |
123 |
1 |
when(iconRenderer.render("icon1", iconSet1)).thenReturn("rendered icon 1"); |
124 |
1 |
when(iconRenderer.renderHTML("icon1", iconSet1)).thenReturn("HTML rendered icon 1"); |
125 |
1 |
when(iconRenderer.render("icon2", iconSet1)).thenReturn(""); |
126 |
1 |
when(iconRenderer.renderHTML("icon2", iconSet1)).thenReturn(""); |
127 |
|
|
128 |
1 |
IconSet defaultIconSet = new IconSet("default"); |
129 |
1 |
defaultIconSet.addIcon("icon2", new Icon("icon")); |
130 |
1 |
when(iconSetManager.getDefaultIconSet()).thenReturn(defaultIconSet); |
131 |
1 |
when(iconRenderer.render("icon1", defaultIconSet)).thenReturn("default rendered icon 1"); |
132 |
1 |
when(iconRenderer.render("icon2", defaultIconSet)).thenReturn("default rendered icon 2"); |
133 |
1 |
when(iconRenderer.renderHTML("icon1", defaultIconSet)).thenReturn("HTML default rendered icon 1"); |
134 |
1 |
when(iconRenderer.renderHTML("icon2", defaultIconSet)).thenReturn("HTML default rendered icon 2"); |
135 |
|
|
136 |
|
|
137 |
1 |
assertEquals("rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet1")); |
138 |
1 |
assertEquals("default rendered icon 2", mocker.getComponentUnderTest().render("icon2", "iconSet1")); |
139 |
1 |
assertEquals("default rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet2")); |
140 |
1 |
assertEquals("rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet1", true)); |
141 |
1 |
assertEquals("default rendered icon 2", mocker.getComponentUnderTest().render("icon2", "iconSet1", true)); |
142 |
1 |
assertEquals("default rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet2", true)); |
143 |
1 |
assertEquals("rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet1", false)); |
144 |
1 |
assertEquals("", mocker.getComponentUnderTest().render("icon2", "iconSet1", false)); |
145 |
1 |
assertEquals("", mocker.getComponentUnderTest().render("icon1", "iconSet2", false)); |
146 |
|
|
147 |
1 |
assertEquals("HTML rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet1")); |
148 |
1 |
assertEquals("HTML default rendered icon 2", mocker.getComponentUnderTest().renderHTML("icon2", "iconSet1")); |
149 |
1 |
assertEquals("HTML default rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet2")); |
150 |
1 |
assertEquals("HTML rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet1", true)); |
151 |
1 |
assertEquals("HTML default rendered icon 2", mocker.getComponentUnderTest().renderHTML("icon2", "iconSet1", true)); |
152 |
1 |
assertEquals("HTML default rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet2", true)); |
153 |
1 |
assertEquals("HTML rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet1", false)); |
154 |
1 |
assertEquals("", mocker.getComponentUnderTest().renderHTML("icon2", "iconSet1", false)); |
155 |
1 |
assertEquals("", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet2", false)); |
156 |
|
} |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
158 |
1 |
@Test... |
159 |
|
public void getIconNames() throws Exception |
160 |
|
{ |
161 |
1 |
IconSet iconSet = new IconSet("iconSet1"); |
162 |
1 |
iconSet.addIcon("icon1", new Icon("icon1 value")); |
163 |
1 |
iconSet.addIcon("icon2", new Icon("icon2 value")); |
164 |
|
|
165 |
|
|
166 |
1 |
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet); |
167 |
1 |
when(iconSetManager.getIconSet("iconSet1")).thenReturn(iconSet); |
168 |
|
|
169 |
|
|
170 |
1 |
List<String> results = mocker.getComponentUnderTest().getIconNames(); |
171 |
1 |
List<String> results2 = mocker.getComponentUnderTest().getIconNames("iconSet1"); |
172 |
|
|
173 |
|
|
174 |
1 |
assertEquals(2, results.size()); |
175 |
1 |
assertTrue(results.contains("icon1")); |
176 |
1 |
assertTrue(results.contains("icon2")); |
177 |
1 |
assertEquals(2, results2.size()); |
178 |
1 |
assertTrue(results2.contains("icon1")); |
179 |
1 |
assertTrue(results2.contains("icon2")); |
180 |
|
} |
181 |
|
} |