1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss.internal.cache; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.cache.Cache; |
26 |
|
import org.xwiki.cache.CacheFactory; |
27 |
|
import org.xwiki.cache.CacheManager; |
28 |
|
import org.xwiki.cache.config.CacheConfiguration; |
29 |
|
import org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference; |
30 |
|
import org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference; |
31 |
|
import org.xwiki.lesscss.internal.skin.FSSkinReference; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
|
34 |
|
import static org.junit.Assert.assertEquals; |
35 |
|
import static org.mockito.ArgumentMatchers.eq; |
36 |
|
import static org.mockito.Mockito.mock; |
37 |
|
import static org.mockito.Mockito.never; |
38 |
|
import static org.mockito.Mockito.times; |
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 (64) |
Complexity: 8 |
Complexity Density: 0.14 |
|
48 |
|
public class DefaultLESSResourcesCacheTest |
49 |
|
{ |
50 |
|
@Rule |
51 |
|
public MockitoComponentMockingRule<DefaultLESSResourcesCache> mocker = |
52 |
|
new MockitoComponentMockingRule<>(DefaultLESSResourcesCache.class); |
53 |
|
|
54 |
|
private CacheManager cacheManager; |
55 |
|
|
56 |
|
private Cache<String> cache; |
57 |
|
|
58 |
|
private CacheKeyFactory cacheKeyFactory; |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
60 |
6 |
@Before... |
61 |
|
public void setUp() throws Exception |
62 |
|
{ |
63 |
6 |
cacheManager = mocker.getInstance(CacheManager.class); |
64 |
6 |
cache = mock(Cache.class); |
65 |
6 |
CacheFactory cacheFactory = mock(CacheFactory.class); |
66 |
6 |
when(cacheManager.getCacheFactory()).thenReturn(cacheFactory); |
67 |
6 |
CacheConfiguration configuration = new CacheConfiguration("lesscss.skinfiles.cache"); |
68 |
6 |
when(cacheFactory.<String>newCache(eq(configuration))).thenReturn(cache); |
69 |
6 |
cacheKeyFactory = mocker.getInstance(CacheKeyFactory.class); |
70 |
|
|
71 |
6 |
LESSSkinFileResourceReference lessSkinFileResourceReference = |
72 |
|
new LESSSkinFileResourceReference("lessResource", null, null); |
73 |
6 |
when(cacheKeyFactory.getCacheKey(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), |
74 |
|
eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("12_lessResource_4_skin_10_colorTheme"); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
19 |
private LESSSkinFileResourceReference createLESSSkinFileResourceReference(String fileName)... |
78 |
|
{ |
79 |
19 |
return new LESSSkinFileResourceReference(fileName, null, null); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void get() throws Exception |
84 |
|
{ |
85 |
|
|
86 |
1 |
when(cache.get("12_lessResource_4_skin_10_colorTheme")).thenReturn("Expected output"); |
87 |
|
|
88 |
|
|
89 |
1 |
String result = mocker.getComponentUnderTest().get(new LESSSkinFileResourceReference("lessResource", null, null), |
90 |
|
new FSSkinReference("skin"), new NamedColorThemeReference("colorTheme")); |
91 |
|
|
92 |
|
|
93 |
1 |
assertEquals("Expected output", result); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
96 |
1 |
@Test... |
97 |
|
public void set() throws Exception |
98 |
|
{ |
99 |
|
|
100 |
1 |
mocker.getComponentUnderTest().set( |
101 |
|
new LESSSkinFileResourceReference("lessResource", null, null), new FSSkinReference("skin"), |
102 |
|
new NamedColorThemeReference("colorTheme"), "css"); |
103 |
|
|
104 |
|
|
105 |
1 |
verify(cache).set(eq("12_lessResource_4_skin_10_colorTheme"), eq("css")); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void clear() throws Exception |
110 |
|
{ |
111 |
|
|
112 |
1 |
mocker.getComponentUnderTest().clear(); |
113 |
|
|
114 |
|
|
115 |
1 |
verify(cache).removeAll(); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
118 |
1 |
@Test... |
119 |
|
public void clearFromSkin() throws Exception |
120 |
|
{ |
121 |
|
|
122 |
1 |
LESSSkinFileResourceReference file1 = createLESSSkinFileResourceReference("file1"); |
123 |
1 |
LESSSkinFileResourceReference file2 = createLESSSkinFileResourceReference("file2"); |
124 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), |
125 |
|
eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("k1"); |
126 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin2")), |
127 |
|
eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("k3"); |
128 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file2), eq(new FSSkinReference("skin1")), |
129 |
|
eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("k4"); |
130 |
|
|
131 |
|
|
132 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
133 |
|
new NamedColorThemeReference("colorTheme"), "css1"); |
134 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
135 |
|
new NamedColorThemeReference("colorTheme"), "css1"); |
136 |
|
|
137 |
|
|
138 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin2"), |
139 |
|
new NamedColorThemeReference("colorTheme"), "css2"); |
140 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file2"), new FSSkinReference("skin1"), |
141 |
|
new NamedColorThemeReference("colorTheme"), "css3"); |
142 |
|
|
143 |
|
|
144 |
1 |
mocker.getComponentUnderTest().clearFromSkin(new FSSkinReference("skin1")); |
145 |
|
|
146 |
|
|
147 |
1 |
verify(cache, times(1)).remove("k1"); |
148 |
1 |
verify(cache).remove("k4"); |
149 |
1 |
verify(cache, never()).remove("k3"); |
150 |
|
} |
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
152 |
1 |
@Test... |
153 |
|
public void clearFromColorTheme() throws Exception |
154 |
|
{ |
155 |
|
|
156 |
1 |
LESSSkinFileResourceReference file1 = createLESSSkinFileResourceReference("file1"); |
157 |
1 |
LESSSkinFileResourceReference file2 = createLESSSkinFileResourceReference("file2"); |
158 |
|
|
159 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), |
160 |
|
eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k1"); |
161 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), |
162 |
|
eq(new NamedColorThemeReference("colorTheme2")), eq(true))).thenReturn("k3"); |
163 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file2), eq(new FSSkinReference("skin2")), |
164 |
|
eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k4"); |
165 |
|
|
166 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
167 |
|
new NamedColorThemeReference("colorTheme1"), "css1"); |
168 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
169 |
|
new NamedColorThemeReference("colorTheme1"), "css1"); |
170 |
|
|
171 |
|
|
172 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
173 |
|
new NamedColorThemeReference("colorTheme2"), "css2"); |
174 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file2"), new FSSkinReference("skin2"), |
175 |
|
new NamedColorThemeReference("colorTheme1"), "css3"); |
176 |
|
|
177 |
|
|
178 |
1 |
mocker.getComponentUnderTest().clearFromColorTheme(new NamedColorThemeReference("colorTheme1")); |
179 |
|
|
180 |
|
|
181 |
1 |
verify(cache, times(1)).remove("k1"); |
182 |
1 |
verify(cache).remove("k4"); |
183 |
1 |
verify(cache, never()).remove("k3"); |
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
186 |
1 |
@Test... |
187 |
|
public void clearFromLESSResource() throws Exception |
188 |
|
{ |
189 |
|
|
190 |
1 |
LESSSkinFileResourceReference file1 = createLESSSkinFileResourceReference("file1"); |
191 |
1 |
LESSSkinFileResourceReference file2 = createLESSSkinFileResourceReference("file2"); |
192 |
|
|
193 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), |
194 |
|
eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k1"); |
195 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file2), eq(new FSSkinReference("skin1")), |
196 |
|
eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k3"); |
197 |
1 |
when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin2")), |
198 |
|
eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k4"); |
199 |
|
|
200 |
|
|
201 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
202 |
|
new NamedColorThemeReference("colorTheme1"), "css1"); |
203 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), |
204 |
|
new NamedColorThemeReference("colorTheme1"), "css1"); |
205 |
|
|
206 |
|
|
207 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file2"), new FSSkinReference("skin1"), |
208 |
|
new NamedColorThemeReference("colorTheme1"), "css"); |
209 |
1 |
mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin2"), |
210 |
|
new NamedColorThemeReference("colorTheme1"), "css3"); |
211 |
|
|
212 |
|
|
213 |
1 |
mocker.getComponentUnderTest().clearFromLESSResource(createLESSSkinFileResourceReference("file1")); |
214 |
|
|
215 |
|
|
216 |
1 |
verify(cache, times(1)).remove("k1"); |
217 |
1 |
verify(cache).remove("k4"); |
218 |
1 |
verify(cache, never()).remove("k3"); |
219 |
|
} |
220 |
|
|
221 |
|
} |