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

File EnumConverterTest.java

 

Code metrics

0
7
6
2
82
48
6
0.86
1.17
3
1

Classes

Class Line # Actions
EnumConverterTest 34 7 0% 6 0
1.0100%
EnumConverterTest.EnumTest 38 0 - 0 0
-1.0 -
 

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.properties.internal.converter;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Test;
25    import org.xwiki.properties.ConverterManager;
26    import org.xwiki.properties.converter.ConversionException;
27    import org.xwiki.test.jmock.AbstractComponentTestCase;
28   
29    /**
30    * Validate {@link EnumConverter} component.
31    *
32    * @version $Id: 95653d90fc401a0fa61dbd9bd60a617c991f2741 $
33    */
 
34    public class EnumConverterTest extends AbstractComponentTestCase
35    {
36    private ConverterManager converterManager;
37   
 
38    public enum EnumTest
39    {
40    VALUE1,
41    Value2
42    }
43   
 
44  5 toggle @Before
45    @Override
46    public void setUp() throws Exception
47    {
48  5 super.setUp();
49   
50  5 this.converterManager = getComponentManager().getInstance(ConverterManager.class);
51    }
52   
 
53  1 toggle @Test
54    public void testConvertValid()
55    {
56  1 Assert.assertEquals(EnumTest.VALUE1, this.converterManager.convert(EnumTest.class, "VALUE1"));
57    }
58   
 
59  1 toggle @Test
60    public void testConvertIgnireCase()
61    {
62  1 Assert.assertEquals(EnumTest.VALUE1, this.converterManager.convert(EnumTest.class, "value1"));
63    }
64   
 
65  1 toggle @Test
66    public void testConvertToString()
67    {
68  1 Assert.assertEquals("VALUE1", this.converterManager.convert(String.class, EnumTest.VALUE1));
69    }
70   
 
71  1 toggle @Test(expected = ConversionException.class)
72    public void testConvertInvalid()
73    {
74  1 this.converterManager.convert(EnumTest.class, "notexistingvalue");
75    }
76   
 
77  1 toggle @Test
78    public void testConvertNull()
79    {
80  1 Assert.assertNull(this.converterManager.convert(EnumTest.class, null));
81    }
82    }