1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.macro.descriptor

File DefaultMacroDescriptorTest.java

 

Code metrics

0
54
18
2
211
147
18
0.33
3
9
1

Classes

Class Line # Actions
DefaultMacroDescriptorTest 39 42 0% 6 0
1.0100%
DefaultMacroDescriptorTest.ParametersTests 41 12 0% 12 14
0.4166666641.7%
 

Contributing tests

This file is covered by 5 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.rendering.macro.descriptor;
21   
22    import java.util.Map;
23   
24    import org.junit.Assert;
25    import org.junit.Before;
26    import org.junit.Test;
27    import org.xwiki.properties.BeanManager;
28    import org.xwiki.properties.annotation.PropertyDescription;
29    import org.xwiki.properties.annotation.PropertyHidden;
30    import org.xwiki.properties.annotation.PropertyMandatory;
31    import org.xwiki.rendering.macro.MacroId;
32    import org.xwiki.test.jmock.AbstractComponentTestCase;
33   
34    /**
35    * Validate {@link DefaultMacroDescriptor} and {@link AbstractMacroDescriptor}.
36    *
37    * @version $Id: faf06d9cfa12470096d9354ebcdd14d3ba4d3479 $
38    */
 
39    public class DefaultMacroDescriptorTest extends AbstractComponentTestCase
40    {
 
41    public static class ParametersTests
42    {
43    private String lowerparam;
44   
45    private String upperParam;
46   
47    private String param1 = "defaultparam1";
48   
49    private int param2;
50   
51    private boolean param3;
52   
53    private String hiddenParameter;
54   
 
55  0 toggle public void setLowerparam(String lowerparam)
56    {
57  0 this.lowerparam = lowerparam;
58    }
59   
 
60  5 toggle public String getLowerparam()
61    {
62  5 return this.lowerparam;
63    }
64   
 
65  0 toggle public void setUpperParam(String upperParam)
66    {
67  0 this.upperParam = upperParam;
68    }
69   
 
70  5 toggle public String getUpperParam()
71    {
72  5 return this.upperParam;
73    }
74   
 
75  0 toggle @PropertyDescription("param1 description")
76    public void setParam1(String param1)
77    {
78  0 this.param1 = param1;
79    }
80   
 
81  5 toggle public String getParam1()
82    {
83  5 return this.param1;
84    }
85   
 
86  0 toggle @PropertyMandatory
87    @PropertyDescription("param2 description")
88    public void setParam2(int param1)
89    {
90  0 this.param2 = param1;
91    }
92   
 
93  5 toggle public int getParam2()
94    {
95  5 return this.param2;
96    }
97   
 
98  0 toggle public void setParam3(boolean param1)
99    {
100  0 this.param3 = param1;
101    }
102   
 
103  5 toggle @PropertyMandatory
104    @PropertyDescription("param3 description")
105    public boolean getParam3()
106    {
107  5 return this.param3;
108    }
109   
 
110  0 toggle @PropertyHidden
111    public void setHiddenParameter(String hiddenParameter)
112    {
113  0 this.hiddenParameter = hiddenParameter;
114    }
115   
 
116  0 toggle public String getHiddenParameter()
117    {
118  0 return this.hiddenParameter;
119    }
120    }
121   
122    private DefaultMacroDescriptor macroDescriptor;
123   
 
124  5 toggle @Before
125    @Override
126    public void setUp() throws Exception
127    {
128  5 super.setUp();
129  5 BeanManager propertiesManager = getComponentManager().getInstance(BeanManager.class);
130  5 this.macroDescriptor =
131    new DefaultMacroDescriptor(new MacroId("Id"), "Name", "Description", new DefaultContentDescriptor(),
132    propertiesManager.getBeanDescriptor(ParametersTests.class));
133    }
134   
 
135  1 toggle @Test
136    public void testParameterDescriptor()
137    {
138  1 Map<String, ParameterDescriptor> map = this.macroDescriptor.getParameterDescriptorMap();
139   
140  1 Assert.assertNull(map.get("hiddenParameter".toLowerCase()));
141   
142  1 ParameterDescriptor lowerParamDescriptor = map.get("lowerparam");
143   
144  1 Assert.assertNotNull(lowerParamDescriptor);
145  1 Assert.assertEquals("lowerparam", lowerParamDescriptor.getId());
146  1 Assert.assertEquals("lowerparam", lowerParamDescriptor.getDescription());
147  1 Assert.assertSame(String.class, lowerParamDescriptor.getParameterType());
148  1 Assert.assertEquals(null, lowerParamDescriptor.getDefaultValue());
149  1 Assert.assertEquals(false, lowerParamDescriptor.isMandatory());
150   
151  1 ParameterDescriptor param1Descriptor = map.get("param1");
152   
153  1 Assert.assertEquals("defaultparam1", param1Descriptor.getDefaultValue());
154    }
155   
 
156  1 toggle @Test
157    public void testParameterDescriptorWithUpperCase()
158    {
159  1 Map<String, ParameterDescriptor> map = this.macroDescriptor.getParameterDescriptorMap();
160   
161  1 ParameterDescriptor upperParamDescriptor = map.get("upperParam".toLowerCase());
162   
163  1 Assert.assertNotNull(upperParamDescriptor);
164  1 Assert.assertEquals("upperParam", upperParamDescriptor.getId());
165  1 Assert.assertEquals("upperParam", upperParamDescriptor.getDescription());
166  1 Assert.assertSame(String.class, upperParamDescriptor.getParameterType());
167  1 Assert.assertEquals(false, upperParamDescriptor.isMandatory());
168    }
169   
 
170  1 toggle @Test
171    public void testParameterDescriptorWithDescription()
172    {
173  1 Map<String, ParameterDescriptor> map = this.macroDescriptor.getParameterDescriptorMap();
174   
175  1 ParameterDescriptor param1Descriptor = map.get("param1".toLowerCase());
176   
177  1 Assert.assertNotNull(param1Descriptor);
178  1 Assert.assertEquals("param1", param1Descriptor.getId());
179  1 Assert.assertEquals("param1 description", param1Descriptor.getDescription());
180  1 Assert.assertSame(String.class, param1Descriptor.getParameterType());
181  1 Assert.assertEquals(false, param1Descriptor.isMandatory());
182    }
183   
 
184  1 toggle @Test
185    public void testParameterDescriptorWithDescriptionAndMandatory()
186    {
187  1 Map<String, ParameterDescriptor> map = this.macroDescriptor.getParameterDescriptorMap();
188   
189  1 ParameterDescriptor param2Descriptor = map.get("param2".toLowerCase());
190   
191  1 Assert.assertNotNull(param2Descriptor);
192  1 Assert.assertEquals("param2", param2Descriptor.getId());
193  1 Assert.assertEquals("param2 description", param2Descriptor.getDescription());
194  1 Assert.assertSame(int.class, param2Descriptor.getParameterType());
195  1 Assert.assertEquals(true, param2Descriptor.isMandatory());
196    }
197   
 
198  1 toggle @Test
199    public void testParameterDescriptorWithDescriptionAndMandatoryOnSetter()
200    {
201  1 Map<String, ParameterDescriptor> map = this.macroDescriptor.getParameterDescriptorMap();
202   
203  1 ParameterDescriptor param3Descriptor = map.get("param3".toLowerCase());
204   
205  1 Assert.assertNotNull(param3Descriptor);
206  1 Assert.assertEquals("param3", param3Descriptor.getId());
207  1 Assert.assertEquals("param3 description", param3Descriptor.getDescription());
208  1 Assert.assertSame(boolean.class, param3Descriptor.getParameterType());
209  1 Assert.assertEquals(true, param3Descriptor.isMandatory());
210    }
211    }