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

File CachedLESSColorThemeConverterTest.java

 

Code metrics

0
11
2
1
82
45
2
0.18
5.5
2
1

Classes

Class Line # Actions
CachedLESSColorThemeConverterTest 48 11 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.colortheme.converter;
21   
22    import java.io.StringWriter;
23    import java.util.Map;
24   
25    import org.apache.commons.io.IOUtils;
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.lesscss.compiler.LESSCompiler;
30    import org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference;
31    import org.xwiki.lesscss.resources.LESSResourceReference;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    import com.github.sommeri.less4j.LessCompiler;
35    import com.github.sommeri.less4j.core.DefaultLessCompiler;
36   
37    import static org.junit.Assert.assertEquals;
38    import static org.mockito.ArgumentMatchers.any;
39    import static org.mockito.ArgumentMatchers.eq;
40    import static org.mockito.Mockito.when;
41   
42    /**
43    * Test class for {@link org.xwiki.lesscss.internal.colortheme.converter.CachedLESSColorThemeConverter}.
44    *
45    * @since 7.0RC1
46    * @version $Id: e1761dc1e9138d87ea3da804823899df07c75f3a $
47    */
 
48    public class CachedLESSColorThemeConverterTest
49    {
50    @Rule
51    public MockitoComponentMockingRule<CachedLESSColorThemeConverter> mocker =
52    new MockitoComponentMockingRule<>(CachedLESSColorThemeConverter.class);
53   
54    private LESSCompiler lessCompiler;
55   
 
56  1 toggle @Before
57    public void setUp() throws Exception
58    {
59  1 lessCompiler = mocker.getInstance(LESSCompiler.class);
60    }
61   
 
62  1 toggle @Test
63    public void compute() throws Exception
64    {
65  1 StringWriter lessSource = new StringWriter();
66  1 IOUtils.copy(getClass().getResourceAsStream("/styleWithColorTheme.less"), lessSource);
67   
68    // To have a better test, we use Less4j to generate the CSS that contains the color theme mapping
69  1 LessCompiler less4jCompiler = new DefaultLessCompiler();
70  1 LessCompiler.Configuration options = new LessCompiler.Configuration();
71  1 options.setCompressing(true);
72  1 LessCompiler.CompilationResult lessResult = less4jCompiler.compile(lessSource.toString(), options);
73  1 when(lessCompiler.compile(any(LESSResourceReference.class), eq(false), eq(false), eq("skin"), eq(false))).
74    thenReturn(lessResult.getCss());
75   
76    // So now we can test the converter on the less4j output
77  1 Map<String, String> results = mocker.getComponentUnderTest().compute(
78    new LESSSkinFileResourceReference("file", null, null), false, false, true, "skin");
79  1 assertEquals("#E8E8E8", results.get("borderColor"));
80  1 assertEquals("#3e444c", results.get("highlightColor"));
81    }
82    }