1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.properties.internal; |
21 |
|
|
22 |
|
import java.lang.reflect.ParameterizedType; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.junit.Assert; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.properties.PropertyDescriptor; |
29 |
|
import org.xwiki.properties.test.TestBean; |
30 |
|
|
31 |
|
|
32 |
|
@link |
33 |
|
|
34 |
|
@version |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (120) |
Complexity: 12 |
Complexity Density: 0.11 |
|
36 |
|
public class DefaultBeanDescriptorTest |
37 |
|
{ |
38 |
|
private DefaultBeanDescriptor beanDescriptor; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
11 |
@Before... |
41 |
|
public void setUp() throws Exception |
42 |
|
{ |
43 |
11 |
this.beanDescriptor = new DefaultBeanDescriptor(TestBean.class); |
44 |
|
} |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
46 |
1 |
@Test... |
47 |
|
public void testPropertyDescriptor() |
48 |
|
{ |
49 |
1 |
Assert.assertNull(this.beanDescriptor.getProperty("hiddenProperty")); |
50 |
|
|
51 |
1 |
PropertyDescriptor lowerPropertyDescriptor = this.beanDescriptor.getProperty("lowerprop"); |
52 |
|
|
53 |
1 |
Assert.assertNotNull(lowerPropertyDescriptor); |
54 |
1 |
Assert.assertEquals("lowerprop", lowerPropertyDescriptor.getId()); |
55 |
1 |
Assert.assertEquals("lowerprop", lowerPropertyDescriptor.getName()); |
56 |
1 |
Assert.assertEquals("lowerprop", lowerPropertyDescriptor.getDescription()); |
57 |
1 |
Assert.assertSame(String.class, lowerPropertyDescriptor.getPropertyClass()); |
58 |
1 |
Assert.assertEquals(null, lowerPropertyDescriptor.getDefaultValue()); |
59 |
1 |
Assert.assertEquals(false, lowerPropertyDescriptor.isMandatory()); |
60 |
1 |
Assert.assertNotNull(lowerPropertyDescriptor.getWriteMethod()); |
61 |
1 |
Assert.assertNotNull(lowerPropertyDescriptor.getReadMethod()); |
62 |
1 |
Assert.assertNull(lowerPropertyDescriptor.getField()); |
63 |
|
|
64 |
1 |
PropertyDescriptor prop1Descriptor = this.beanDescriptor.getProperty("prop1"); |
65 |
|
|
66 |
1 |
Assert.assertEquals("defaultprop1", prop1Descriptor.getDefaultValue()); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
69 |
1 |
@Test... |
70 |
|
public void testPropertyDescriptorWithUpperCase() |
71 |
|
{ |
72 |
1 |
PropertyDescriptor upperPropertyDescriptor = this.beanDescriptor.getProperty("upperProp"); |
73 |
|
|
74 |
1 |
Assert.assertNotNull(upperPropertyDescriptor); |
75 |
1 |
Assert.assertEquals("upperProp", upperPropertyDescriptor.getId()); |
76 |
1 |
Assert.assertEquals("upperProp", upperPropertyDescriptor.getName()); |
77 |
1 |
Assert.assertEquals("upperProp", upperPropertyDescriptor.getDescription()); |
78 |
1 |
Assert.assertSame(String.class, upperPropertyDescriptor.getPropertyClass()); |
79 |
1 |
Assert.assertEquals(false, upperPropertyDescriptor.isMandatory()); |
80 |
1 |
Assert.assertNotNull(upperPropertyDescriptor.getWriteMethod()); |
81 |
1 |
Assert.assertNotNull(upperPropertyDescriptor.getReadMethod()); |
82 |
1 |
Assert.assertNull(upperPropertyDescriptor.getField()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void testPropertyDescriptorPublicField() |
87 |
|
{ |
88 |
1 |
PropertyDescriptor publicFieldPropertyDescriptor = this.beanDescriptor.getProperty("publicField"); |
89 |
|
|
90 |
1 |
Assert.assertNotNull(publicFieldPropertyDescriptor); |
91 |
1 |
Assert.assertEquals("publicField", publicFieldPropertyDescriptor.getId()); |
92 |
1 |
Assert.assertEquals("Public Field", publicFieldPropertyDescriptor.getName()); |
93 |
1 |
Assert.assertEquals("a public field", publicFieldPropertyDescriptor.getDescription()); |
94 |
1 |
Assert.assertSame(String.class, publicFieldPropertyDescriptor.getPropertyClass()); |
95 |
1 |
Assert.assertEquals(false, publicFieldPropertyDescriptor.isMandatory()); |
96 |
1 |
Assert.assertNull(publicFieldPropertyDescriptor.getWriteMethod()); |
97 |
1 |
Assert.assertNull(publicFieldPropertyDescriptor.getReadMethod()); |
98 |
1 |
Assert.assertNotNull(publicFieldPropertyDescriptor.getField()); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void testPropertyDescriptorPublicStaticField() |
103 |
|
{ |
104 |
1 |
Assert.assertNull(this.beanDescriptor.getProperty("STATICFIELD")); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void testPropertyDescriptorWithDescription() |
109 |
|
{ |
110 |
1 |
PropertyDescriptor prop1Descriptor = this.beanDescriptor.getProperty("prop1"); |
111 |
|
|
112 |
1 |
Assert.assertNotNull(prop1Descriptor); |
113 |
1 |
Assert.assertEquals("prop1", prop1Descriptor.getId()); |
114 |
1 |
Assert.assertEquals("prop1 description", prop1Descriptor.getDescription()); |
115 |
1 |
Assert.assertSame(String.class, prop1Descriptor.getPropertyClass()); |
116 |
1 |
Assert.assertEquals(false, prop1Descriptor.isMandatory()); |
117 |
1 |
Assert.assertNotNull(prop1Descriptor.getWriteMethod()); |
118 |
1 |
Assert.assertNotNull(prop1Descriptor.getReadMethod()); |
119 |
1 |
Assert.assertNull(prop1Descriptor.getField()); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
public void testPropertyDescriptorWithDescriptionAndMandatory() |
124 |
|
{ |
125 |
1 |
PropertyDescriptor prop2Descriptor = this.beanDescriptor.getProperty("prop2"); |
126 |
|
|
127 |
1 |
Assert.assertNotNull(prop2Descriptor); |
128 |
1 |
Assert.assertEquals("prop2", prop2Descriptor.getId()); |
129 |
1 |
Assert.assertEquals("prop2 description", prop2Descriptor.getDescription()); |
130 |
1 |
Assert.assertSame(int.class, prop2Descriptor.getPropertyClass()); |
131 |
1 |
Assert.assertEquals(true, prop2Descriptor.isMandatory()); |
132 |
1 |
Assert.assertNotNull(prop2Descriptor.getWriteMethod()); |
133 |
1 |
Assert.assertNotNull(prop2Descriptor.getReadMethod()); |
134 |
1 |
Assert.assertNull(prop2Descriptor.getField()); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
137 |
1 |
@Test... |
138 |
|
public void testPropertyDescriptorWithDescriptionAndMandatoryOnSetter() |
139 |
|
{ |
140 |
1 |
PropertyDescriptor prop3Descriptor = this.beanDescriptor.getProperty("prop3"); |
141 |
|
|
142 |
1 |
Assert.assertNotNull(prop3Descriptor); |
143 |
1 |
Assert.assertEquals("prop3", prop3Descriptor.getId()); |
144 |
1 |
Assert.assertEquals("prop3 description", prop3Descriptor.getDescription()); |
145 |
1 |
Assert.assertSame(boolean.class, prop3Descriptor.getPropertyClass()); |
146 |
1 |
Assert.assertEquals(true, prop3Descriptor.isMandatory()); |
147 |
1 |
Assert.assertNotNull(prop3Descriptor.getWriteMethod()); |
148 |
1 |
Assert.assertNotNull(prop3Descriptor.getReadMethod()); |
149 |
1 |
Assert.assertNull(prop3Descriptor.getField()); |
150 |
|
} |
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
152 |
1 |
@Test... |
153 |
|
public void testPropertyDescriptorGeneric() |
154 |
|
{ |
155 |
1 |
PropertyDescriptor genericPropertyDescriptor = this.beanDescriptor.getProperty("genericProp"); |
156 |
|
|
157 |
1 |
Assert.assertNotNull(genericPropertyDescriptor); |
158 |
1 |
Assert.assertEquals("genericProp", genericPropertyDescriptor.getId()); |
159 |
1 |
Assert.assertEquals("genericProp", genericPropertyDescriptor.getName()); |
160 |
1 |
Assert.assertEquals("genericProp", genericPropertyDescriptor.getDescription()); |
161 |
1 |
Assert.assertSame(List.class, ((ParameterizedType) genericPropertyDescriptor.getPropertyType()).getRawType()); |
162 |
1 |
Assert.assertSame(Integer.class, |
163 |
|
((ParameterizedType) genericPropertyDescriptor.getPropertyType()).getActualTypeArguments()[0]); |
164 |
1 |
Assert.assertEquals(null, genericPropertyDescriptor.getDefaultValue()); |
165 |
1 |
Assert.assertEquals(false, genericPropertyDescriptor.isMandatory()); |
166 |
1 |
Assert.assertNotNull(genericPropertyDescriptor.getWriteMethod()); |
167 |
1 |
Assert.assertNotNull(genericPropertyDescriptor.getReadMethod()); |
168 |
1 |
Assert.assertNull(genericPropertyDescriptor.getField()); |
169 |
|
|
170 |
1 |
PropertyDescriptor prop1Descriptor = this.beanDescriptor.getProperty("prop1"); |
171 |
|
|
172 |
1 |
Assert.assertEquals("defaultprop1", prop1Descriptor.getDefaultValue()); |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
175 |
1 |
@Test... |
176 |
|
public void testPropertyDescriptorGenericField() |
177 |
|
{ |
178 |
1 |
PropertyDescriptor genericFieldPropertyDescriptor = this.beanDescriptor.getProperty("genericField"); |
179 |
|
|
180 |
1 |
Assert.assertNotNull(genericFieldPropertyDescriptor); |
181 |
1 |
Assert.assertEquals("genericField", genericFieldPropertyDescriptor.getId()); |
182 |
1 |
Assert.assertEquals("genericField", genericFieldPropertyDescriptor.getName()); |
183 |
1 |
Assert.assertEquals("genericField", genericFieldPropertyDescriptor.getDescription()); |
184 |
1 |
Assert.assertSame(List.class, |
185 |
|
((ParameterizedType) genericFieldPropertyDescriptor.getPropertyType()).getRawType()); |
186 |
1 |
Assert.assertSame(Integer.class, |
187 |
|
((ParameterizedType) genericFieldPropertyDescriptor.getPropertyType()).getActualTypeArguments()[0]); |
188 |
1 |
Assert.assertEquals(false, genericFieldPropertyDescriptor.isMandatory()); |
189 |
1 |
Assert.assertNull(genericFieldPropertyDescriptor.getWriteMethod()); |
190 |
1 |
Assert.assertNull(genericFieldPropertyDescriptor.getReadMethod()); |
191 |
1 |
Assert.assertNotNull(genericFieldPropertyDescriptor.getField()); |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
194 |
1 |
@Test... |
195 |
|
public void testPropertyDescriptorFieldWithDifferentId() |
196 |
|
{ |
197 |
1 |
PropertyDescriptor propertyDescriptor = this.beanDescriptor.getProperty("impossible.field.name"); |
198 |
|
|
199 |
1 |
Assert.assertNotNull(propertyDescriptor); |
200 |
1 |
Assert.assertEquals("impossible.field.name", propertyDescriptor.getId()); |
201 |
1 |
Assert.assertEquals("impossible.field.name", propertyDescriptor.getName()); |
202 |
1 |
Assert.assertEquals("impossible.field.name", propertyDescriptor.getDescription()); |
203 |
1 |
Assert.assertSame(String.class, propertyDescriptor.getPropertyType()); |
204 |
1 |
Assert.assertEquals(false, propertyDescriptor.isMandatory()); |
205 |
1 |
Assert.assertNull(propertyDescriptor.getWriteMethod()); |
206 |
1 |
Assert.assertNull(propertyDescriptor.getReadMethod()); |
207 |
1 |
Assert.assertNotNull(propertyDescriptor.getField()); |
208 |
|
} |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
210 |
1 |
@Test... |
211 |
|
public void testPropertyDescriptorMethodWithDifferentId() |
212 |
|
{ |
213 |
1 |
PropertyDescriptor propertyDescriptor = this.beanDescriptor.getProperty("impossible.method.name"); |
214 |
|
|
215 |
1 |
Assert.assertNotNull(propertyDescriptor); |
216 |
1 |
Assert.assertEquals("impossible.method.name", propertyDescriptor.getId()); |
217 |
1 |
Assert.assertEquals("impossible.method.name", propertyDescriptor.getName()); |
218 |
1 |
Assert.assertEquals("propertyWithDifferentId", propertyDescriptor.getDescription()); |
219 |
1 |
Assert.assertSame(String.class, propertyDescriptor.getPropertyType()); |
220 |
1 |
Assert.assertEquals(false, propertyDescriptor.isMandatory()); |
221 |
1 |
Assert.assertNotNull(propertyDescriptor.getWriteMethod()); |
222 |
1 |
Assert.assertNotNull(propertyDescriptor.getReadMethod()); |
223 |
1 |
Assert.assertNull(propertyDescriptor.getField()); |
224 |
|
} |
225 |
|
} |