1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link@link |
36 |
|
|
37 |
|
@version |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (48) |
Complexity: 6 |
Complexity Density: 0.14 |
|
39 |
|
public class DefaultMacroDescriptorTest extends AbstractComponentTestCase |
40 |
|
{ |
|
|
| 41.7% |
Uncovered Elements: 14 (24) |
Complexity: 12 |
Complexity Density: 1 |
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0 |
public void setLowerparam(String lowerparam)... |
56 |
|
{ |
57 |
0 |
this.lowerparam = lowerparam; |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
5 |
public String getLowerparam()... |
61 |
|
{ |
62 |
5 |
return this.lowerparam; |
63 |
|
} |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
0 |
public void setUpperParam(String upperParam)... |
66 |
|
{ |
67 |
0 |
this.upperParam = upperParam; |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
5 |
public String getUpperParam()... |
71 |
|
{ |
72 |
5 |
return this.upperParam; |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
@PropertyDescription("param1 description")... |
76 |
|
public void setParam1(String param1) |
77 |
|
{ |
78 |
0 |
this.param1 = param1; |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
5 |
public String getParam1()... |
82 |
|
{ |
83 |
5 |
return this.param1; |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0 |
@PropertyMandatory... |
87 |
|
@PropertyDescription("param2 description") |
88 |
|
public void setParam2(int param1) |
89 |
|
{ |
90 |
0 |
this.param2 = param1; |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
5 |
public int getParam2()... |
94 |
|
{ |
95 |
5 |
return this.param2; |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
public void setParam3(boolean param1)... |
99 |
|
{ |
100 |
0 |
this.param3 = param1; |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
5 |
@PropertyMandatory... |
104 |
|
@PropertyDescription("param3 description") |
105 |
|
public boolean getParam3() |
106 |
|
{ |
107 |
5 |
return this.param3; |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
0 |
@PropertyHidden... |
111 |
|
public void setHiddenParameter(String hiddenParameter) |
112 |
|
{ |
113 |
0 |
this.hiddenParameter = hiddenParameter; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0 |
public String getHiddenParameter()... |
117 |
|
{ |
118 |
0 |
return this.hiddenParameter; |
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
|
private DefaultMacroDescriptor macroDescriptor; |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
124 |
5 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
135 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
156 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
170 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
184 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
198 |
1 |
@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 |
|
} |