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.resources; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Test; |
24 |
|
import org.xwiki.lesscss.compiler.LESSCompilerException; |
25 |
|
import org.xwiki.skin.Skin; |
26 |
|
import org.xwiki.skin.SkinManager; |
27 |
|
import org.xwiki.template.Template; |
28 |
|
import org.xwiki.template.TemplateContent; |
29 |
|
import org.xwiki.template.TemplateManager; |
30 |
|
|
31 |
|
import static org.junit.Assert.assertEquals; |
32 |
|
import static org.junit.Assert.assertNotNull; |
33 |
|
import static org.mockito.Mockito.mock; |
34 |
|
import static org.mockito.Mockito.when; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@since |
40 |
|
@version |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 7 |
Complexity Density: 0.22 |
|
42 |
|
public class LESSSkinFileResourceReferenceTest |
43 |
|
{ |
44 |
|
private TemplateManager templateManager; |
45 |
|
|
46 |
|
private SkinManager skinManager; |
47 |
|
|
48 |
|
private Skin skin; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
50 |
4 |
@Before... |
51 |
|
public void setUp() throws Exception |
52 |
|
{ |
53 |
4 |
templateManager = mock(TemplateManager.class); |
54 |
4 |
skinManager = mock(SkinManager.class); |
55 |
4 |
skin = mock(Skin.class); |
56 |
4 |
when(skinManager.getSkin("skin")).thenReturn(skin); |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void getContent() throws Exception |
61 |
|
{ |
62 |
1 |
LESSSkinFileResourceReference lessSkinFileResourceReference |
63 |
|
= new LESSSkinFileResourceReference("style.less", templateManager, skinManager); |
64 |
|
|
65 |
|
|
66 |
1 |
Template template = mock(Template.class); |
67 |
1 |
when(templateManager.getTemplate("less/style.less", skin)).thenReturn(template); |
68 |
1 |
TemplateContent templateContent = mock(TemplateContent.class); |
69 |
1 |
when(template.getContent()).thenReturn(templateContent); |
70 |
1 |
when(templateContent.getContent()).thenReturn("// My LESS file"); |
71 |
|
|
72 |
|
|
73 |
1 |
assertEquals("// My LESS file", lessSkinFileResourceReference.getContent("skin")); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
76 |
1 |
@Test... |
77 |
|
public void getContentWhenFileDoesNotExist() throws Exception |
78 |
|
{ |
79 |
1 |
LESSSkinFileResourceReference lessSkinFileResourceReference |
80 |
|
= new LESSSkinFileResourceReference("not-existing-file.less", templateManager, skinManager); |
81 |
|
|
82 |
|
|
83 |
1 |
LESSCompilerException caughtException = null; |
84 |
1 |
try { |
85 |
1 |
lessSkinFileResourceReference.getContent("skin"); |
86 |
|
} catch (LESSCompilerException e) { |
87 |
1 |
caughtException = e; |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
1 |
assertNotNull(caughtException); |
92 |
1 |
assertEquals("The template [not-existing-file.less] does not exists.", caughtException.getMessage()); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
1PASS
|
|
95 |
1 |
@Test... |
96 |
|
public void getContentWhenException() throws Exception |
97 |
|
{ |
98 |
1 |
LESSSkinFileResourceReference lessSkinFileResourceReference |
99 |
|
= new LESSSkinFileResourceReference("file.less", templateManager, skinManager); |
100 |
|
|
101 |
|
|
102 |
1 |
Template template = mock(Template.class); |
103 |
1 |
when(templateManager.getTemplate("less/file.less", skin)).thenReturn(template); |
104 |
1 |
Exception exception = new Exception("exception"); |
105 |
1 |
when(template.getContent()).thenThrow(exception); |
106 |
|
|
107 |
|
|
108 |
1 |
LESSCompilerException caughtException = null; |
109 |
1 |
try { |
110 |
1 |
lessSkinFileResourceReference.getContent("skin"); |
111 |
|
} catch (LESSCompilerException e) { |
112 |
1 |
caughtException = e; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
1 |
assertNotNull(caughtException); |
117 |
1 |
assertEquals("Failed to get the content of the template [file.less].", caughtException.getMessage()); |
118 |
1 |
assertEquals(exception, caughtException.getCause()); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void serialize() throws Exception |
123 |
|
{ |
124 |
1 |
LESSSkinFileResourceReference lessSkinFileResourceReference |
125 |
|
= new LESSSkinFileResourceReference("file.less", templateManager, skinManager); |
126 |
|
|
127 |
|
|
128 |
1 |
assertEquals("LessSkinFile[file.less]", lessSkinFileResourceReference.serialize()); |
129 |
|
} |
130 |
|
} |