1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.properties.internal

File DefaultBeanManagerTest.java

 

Code metrics

0
26
5
2
117
76
5
0.19
5.2
2.5
1

Classes

Class Line # Actions
DefaultBeanManagerTest 49 25 0% 4 0
1.0100%
DefaultBeanManagerTest.RawPropertiesTest 51 1 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 3 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.util.Arrays;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.junit.Assert;
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.component.internal.ContextComponentManagerProvider;
31    import org.xwiki.properties.BeanManager;
32    import org.xwiki.properties.PropertyException;
33    import org.xwiki.properties.PropertyMandatoryException;
34    import org.xwiki.properties.RawProperties;
35    import org.xwiki.properties.internal.converter.ConvertUtilsConverter;
36    import org.xwiki.properties.internal.converter.EnumConverter;
37    import org.xwiki.properties.test.GenericTestConverter;
38    import org.xwiki.properties.test.TestBean;
39    import org.xwiki.test.ComponentManagerRule;
40    import org.xwiki.test.annotation.ComponentList;
41   
42    /**
43    * Validate {@link DefaultBeanManager}.
44    *
45    * @version $Id: c4aa4fffe2a60d3711ca417e63d39116e186dc48 $
46    */
47    @ComponentList({ DefaultBeanManager.class, DefaultConverterManager.class, EnumConverter.class,
48    ConvertUtilsConverter.class, ContextComponentManagerProvider.class, GenericTestConverter.class })
 
49    public class DefaultBeanManagerTest
50    {
 
51    public static class RawPropertiesTest extends HashMap<String, Object> implements RawProperties
52    {
 
53  2 toggle @Override
54    public void set(String propertyName, Object value)
55    {
56  2 put(propertyName, value);
57    }
58    }
59   
60    @Rule
61    public final ComponentManagerRule componentManager = new ComponentManagerRule();
62   
63    private BeanManager defaultBeanManager;
64   
 
65  3 toggle @Before
66    public void setUp() throws Exception
67    {
68  3 this.defaultBeanManager = this.componentManager.getInstance(BeanManager.class);
69    }
70   
 
71  1 toggle @Test
72    public void testPopulate() throws PropertyException
73    {
74  1 TestBean beanTest = new TestBean();
75   
76  1 Map<String, String> values = new HashMap<String, String>();
77   
78  1 values.put("lowerprop", "lowerpropvalue");
79  1 values.put("upperprop", "upperPropvalue");
80  1 values.put("prop2", "42");
81  1 values.put("prop3", "true");
82  1 values.put("hiddenProperty", "hiddenPropertyvalue");
83  1 values.put("publicField", "publicFieldvalue");
84  1 values.put("genericProp", "1,2");
85   
86  1 this.defaultBeanManager.populate(beanTest, values);
87   
88  1 Assert.assertEquals("lowerpropvalue", beanTest.getLowerprop());
89  1 Assert.assertEquals("upperPropvalue", beanTest.getUpperProp());
90  1 Assert.assertEquals(42, beanTest.getProp2());
91  1 Assert.assertTrue(beanTest.getProp3());
92  1 Assert.assertNull(beanTest.getHiddenProperty());
93  1 Assert.assertEquals("publicFieldvalue", beanTest.publicField);
94  1 Assert.assertEquals(Arrays.asList(1, 2), beanTest.getGenericProp());
95    }
96   
 
97  1 toggle @Test(expected = PropertyMandatoryException.class)
98    public void testPopulateWhenMissingMandatoryProperty() throws PropertyException
99    {
100  1 this.defaultBeanManager.populate(new TestBean(), new HashMap<String, String>());
101    }
102   
 
103  1 toggle @Test
104    public void testPopulateRawProperties() throws PropertyException
105    {
106  1 Map<String, Object> values = new HashMap<String, Object>();
107   
108  1 values.put("pro1", "value1");
109  1 values.put("prop2", 2);
110   
111  1 RawPropertiesTest bean = new RawPropertiesTest();
112   
113  1 this.defaultBeanManager.populate(bean, values);
114   
115  1 Assert.assertEquals(values, bean);
116    }
117    }