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

File SetConverterTest.java

 

Code metrics

0
7
2
1
75
39
2
0.29
3.5
2
1

Classes

Class Line # Actions
SetConverterTest 38 7 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.HashSet;
24    import java.util.LinkedHashSet;
25    import java.util.Set;
26   
27    import org.junit.Assert;
28    import org.junit.Before;
29    import org.junit.Test;
30    import org.xwiki.properties.ConverterManager;
31    import org.xwiki.test.jmock.AbstractComponentTestCase;
32   
33    /**
34    * Validate {@link HashSetConverter} component.
35    *
36    * @version $Id: 76b292545777588b8ba28fb20d2e19376ae147d9 $
37    */
 
38    public class SetConverterTest extends AbstractComponentTestCase
39    {
40    private ConverterManager converterManager;
41   
42    public Set<Integer> setField1;
43   
44    public Set<Set<Integer>> setField2;
45   
 
46  1 toggle @Before
47    @Override
48    public void setUp() throws Exception
49    {
50  1 super.setUp();
51   
52  1 this.converterManager = getComponentManager().getInstance(ConverterManager.class);
53    }
54   
 
55  1 toggle @Test
56    public void testConvert() throws SecurityException, NoSuchFieldException
57    {
58  1 Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList("1", "2", "3")),
59    this.converterManager.convert(Set.class, "1, 2, 3"));
60   
61  1 Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList("1", "\n", "2", "\n", "3")),
62    this.converterManager.convert(Set.class, "1,\n 2,\n 3"));
63   
64  1 Assert.assertEquals(
65    new LinkedHashSet<Integer>(Arrays.asList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3))),
66    this.converterManager.convert(SetConverterTest.class.getField("setField1").getGenericType(), "1, 2, 3"));
67   
68  1 Assert.assertEquals(
69    new LinkedHashSet<Set<Integer>>(Arrays.asList(new LinkedHashSet<Integer>(Arrays.asList(1, 2, 3)),
70    new LinkedHashSet<Integer>(Arrays.asList(4, 5, 6)))), this.converterManager.convert(
71    SetConverterTest.class.getField("setField2").getGenericType(), "'\\'1\\', 2, 3', \"4, 5, 6\""));
72   
73  1 Assert.assertEquals(new HashSet<String>(Arrays.asList("1:2")), this.converterManager.convert(Set.class, "1:2"));
74    }
75    }