1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.lesscss.internal.resources

File LESSSkinFileResourceReferenceTest.java

 

Code metrics

0
32
5
1
130
79
7
0.22
6.4
5
1.4

Classes

Class Line # Actions
LESSSkinFileResourceReferenceTest 42 32 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Test class for {@link LESSSkinFileResourceReference}.
38    *
39    * @since 7.0RC1
40    * @version $Id: 819d3e49a2d873709fc0d4dce5317934f263d032 $
41    */
 
42    public class LESSSkinFileResourceReferenceTest
43    {
44    private TemplateManager templateManager;
45   
46    private SkinManager skinManager;
47   
48    private Skin skin;
49   
 
50  4 toggle @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   
 
59  1 toggle @Test
60    public void getContent() throws Exception
61    {
62  1 LESSSkinFileResourceReference lessSkinFileResourceReference
63    = new LESSSkinFileResourceReference("style.less", templateManager, skinManager);
64   
65    // Mocks
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    // Test
73  1 assertEquals("// My LESS file", lessSkinFileResourceReference.getContent("skin"));
74    }
75   
 
76  1 toggle @Test
77    public void getContentWhenFileDoesNotExist() throws Exception
78    {
79  1 LESSSkinFileResourceReference lessSkinFileResourceReference
80    = new LESSSkinFileResourceReference("not-existing-file.less", templateManager, skinManager);
81   
82    // Test
83  1 LESSCompilerException caughtException = null;
84  1 try {
85  1 lessSkinFileResourceReference.getContent("skin");
86    } catch (LESSCompilerException e) {
87  1 caughtException = e;
88    }
89   
90    // Verify
91  1 assertNotNull(caughtException);
92  1 assertEquals("The template [not-existing-file.less] does not exists.", caughtException.getMessage());
93    }
94   
 
95  1 toggle @Test
96    public void getContentWhenException() throws Exception
97    {
98  1 LESSSkinFileResourceReference lessSkinFileResourceReference
99    = new LESSSkinFileResourceReference("file.less", templateManager, skinManager);
100   
101    // Mocks
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    // Test
108  1 LESSCompilerException caughtException = null;
109  1 try {
110  1 lessSkinFileResourceReference.getContent("skin");
111    } catch (LESSCompilerException e) {
112  1 caughtException = e;
113    }
114   
115    // Verify
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   
 
121  1 toggle @Test
122    public void serialize() throws Exception
123    {
124  1 LESSSkinFileResourceReference lessSkinFileResourceReference
125    = new LESSSkinFileResourceReference("file.less", templateManager, skinManager);
126   
127    // Test
128  1 assertEquals("LessSkinFile[file.less]", lessSkinFileResourceReference.serialize());
129    }
130    }