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

File DefaultBeanDescriptorTest.java

 

Code metrics

0
108
12
1
225
171
12
0.11
9
12
1

Classes

Class Line # Actions
DefaultBeanDescriptorTest 36 108 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 11 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.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    * Validate {@link DefaultBeanDescriptor}.
33    *
34    * @version $Id: 45c1a5effb35736d268bbbe437d4b92ca6d301a6 $
35    */
 
36    public class DefaultBeanDescriptorTest
37    {
38    private DefaultBeanDescriptor beanDescriptor;
39   
 
40  11 toggle @Before
41    public void setUp() throws Exception
42    {
43  11 this.beanDescriptor = new DefaultBeanDescriptor(TestBean.class);
44    }
45   
 
46  1 toggle @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   
 
69  1 toggle @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   
 
85  1 toggle @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   
 
101  1 toggle @Test
102    public void testPropertyDescriptorPublicStaticField()
103    {
104  1 Assert.assertNull(this.beanDescriptor.getProperty("STATICFIELD"));
105    }
106   
 
107  1 toggle @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   
 
122  1 toggle @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   
 
137  1 toggle @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   
 
152  1 toggle @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   
 
175  1 toggle @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   
 
194  1 toggle @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   
 
210  1 toggle @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    }