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

File ListConverterTest.java

 

Code metrics

0
14
5
1
107
62
5
0.36
2.8
5
1

Classes

Class Line # Actions
ListConverterTest 41 14 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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 java.util.Arrays;
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.component.util.DefaultParameterizedType;
29    import org.xwiki.properties.ConverterManager;
30    import org.xwiki.test.jmock.AbstractComponentTestCase;
31   
32    import com.google.common.reflect.TypeToken;
33   
34    import static org.junit.Assert.assertEquals;
35   
36    /**
37    * Validate {@link ListConverter} component.
38    *
39    * @version $Id: f60f415ae4a41cc9873debf8c1517b78e9591f93 $
40    */
 
41    public class ListConverterTest extends AbstractComponentTestCase
42    {
43    private ConverterManager converterManager;
44   
45    public List<Integer> listField1;
46   
47    public List<List<Integer>> listField2;
48   
 
49  4 toggle @Before
50    @Override
51    public void setUp() throws Exception
52    {
53  4 super.setUp();
54   
55  4 this.converterManager = getComponentManager().getInstance(ConverterManager.class);
56    }
57   
 
58  1 toggle @Test
59    public void testConvertFromString() throws SecurityException, NoSuchFieldException
60    {
61  1 Assert.assertEquals(Arrays.asList("1", "2", "3"), this.converterManager.convert(List.class, "1, 2, 3"));
62   
63  1 Assert.assertEquals(Arrays.asList("1", "\n", "2", "\n", "3"),
64    this.converterManager.convert(List.class, "1,\n 2,\n 3"));
65   
66  1 Assert.assertEquals(Arrays.asList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)),
67    this.converterManager.convert(ListConverterTest.class.getField("listField1").getGenericType(), "1, 2, 3"));
68   
69  1 Assert.assertEquals(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6)), this.converterManager
70    .convert(ListConverterTest.class.getField("listField2").getGenericType(), "'\\'1\\', 2, 3', \"4, 5, 6\""));
71   
72  1 Assert.assertEquals(Arrays.asList("1:2"), this.converterManager.convert(List.class, "1:2"));
73   
74  1 assertEquals(Arrays.asList(1, 2, 3),
75    this.converterManager.convert(new DefaultParameterizedType(null, List.class, Integer.class), "1, 2, 3"));
76   
77  1 assertEquals(Arrays.asList(1, 2, 3), this.converterManager.convert(new TypeToken<List<? extends Integer>>()
78    {
79    }.getType(), "1, 2, 3"));
80   
81  1 assertEquals(Arrays.asList("1", "2", "3"), this.converterManager.convert(new TypeToken<List<?>>()
82    {
83    }.getType(), "1, 2, 3"));
84    }
85   
 
86  1 toggle @Test
87    public void testConvertFromIterable() throws SecurityException
88    {
89  1 assertEquals(Arrays.asList(1, 2, 3), this.converterManager
90    .convert(new DefaultParameterizedType(null, List.class, Integer.class), Arrays.asList("1", "2", "3")));
91    }
92   
 
93  1 toggle @Test
94    public void testConvertFromArray() throws SecurityException
95    {
96  1 assertEquals(Arrays.asList(1, 2, 3), this.converterManager
97    .convert(new DefaultParameterizedType(null, List.class, Integer.class), new String[] { "1", "2", "3" }));
98    }
99   
 
100  1 toggle @Test
101    public void testConvertFromList()
102    {
103  1 List<String> expect = Arrays.asList("1", "2", "3");
104   
105  1 Assert.assertSame(expect, this.converterManager.convert(List.class, expect));
106    }
107    }