1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.objects.classes

File ListClassTest.java

 

Code metrics

0
10
10
1
125
59
10
1
1
10
1

Classes

Class Line # Actions
ListClassTest 32 10 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 10 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 com.xpn.xwiki.objects.classes;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26   
27    /**
28    * Unit tests for {@link ListClass}.
29    *
30    * @version $Id: bb9656ef1ef50077475ea1069313c4a850c6b4b9 $
31    */
 
32    public class ListClassTest
33    {
34    /**
35    * Test that the default separator {@link ListClass#DEFAULT_SEPARATOR} is used when not specified.
36    */
 
37  1 toggle @Test
38    public void testGetListFromStringDefaultSeparator()
39    {
40  1 Assert.assertEquals(Arrays.asList("a", "b", "c"), ListClass.getListFromString("a|b|c"));
41    }
42   
43    /**
44    * Test that the separator can be escaped inside the list item.
45    */
 
46  1 toggle @Test
47    public void testGetListFromStringSeparatorInValues()
48    {
49  1 Assert.assertEquals(Arrays.asList("a", "|b", "c|", "|"), ListClass.getListFromString("a|\\|b|c\\||\\|"));
50    }
51   
52    /**
53    * Test that custom separators work.
54    */
 
55  1 toggle @Test
56    public void testGetListFromStringNonDefaultSeparator()
57    {
58  1 Assert.assertEquals(Arrays.asList("a", "b", "c"), ListClass.getListFromString("a*b*c", "*", false));
59    }
60   
61    /**
62    * Test that we can use more than one separator.
63    */
 
64  1 toggle @Test
65    public void testGetListFromStringMultipleSeparators()
66    {
67  1 Assert.assertEquals(Arrays.asList("a", "b", "c", "d", "e"),
68    ListClass.getListFromString("a*b,c,d*e", "*,", false));
69    }
70   
71    /**
72    * Test that escaped separators in list values work with multipel separators as well.
73    */
 
74  1 toggle @Test
75    public void testGetListFromStringMultipleSeparatorsWithSeparatorsInValues()
76    {
77  1 Assert.assertEquals(Arrays.asList("a*b", "c,d", "e*f"),
78    ListClass.getListFromString("a\\*b,c\\,d*e\\*f", "*,", false));
79    }
80   
81    /**
82    * Test that the default separator {@link ListClass#DEFAULT_SEPARATOR} is used when not specified.
83    */
 
84  1 toggle @Test
85    public void testGetStringFromListDefaultSeparator()
86    {
87  1 Assert.assertEquals("a|b|c", ListClass.getStringFromList(Arrays.asList("a", "b", "c")));
88    }
89   
90    /**
91    * Test that the separator can be escaped inside the list item.
92    */
 
93  1 toggle @Test
94    public void testGetStringFromListSeparatorInValues()
95    {
96  1 Assert.assertEquals("a|\\|b|c\\||\\|", ListClass.getStringFromList(Arrays.asList("a", "|b", "c|", "|")));
97    }
98   
99    /**
100    * Test that custom separators work.
101    */
 
102  1 toggle @Test
103    public void testGetStringFromListNonDefaultSeparator()
104    {
105  1 Assert.assertEquals("a*b*c", ListClass.getStringFromList(Arrays.asList("a", "b", "c"), "*"));
106    }
107   
108    /**
109    * Test that we can use more than one separator.
110    */
 
111  1 toggle @Test
112    public void testGetStringFromListMultipleSeparators()
113    {
114  1 Assert.assertEquals("a*b*c*d*e", ListClass.getStringFromList(Arrays.asList("a", "b", "c", "d", "e"), "*,"));
115    }
116   
117    /**
118    * Test that escaped separators in list values work with multipel separators as well.
119    */
 
120  1 toggle @Test
121    public void testGetStringFromListMultipleSeparatorsWithSeparatorsInValues()
122    {
123  1 Assert.assertEquals("a\\*b*c\\,d*e\\*f", ListClass.getStringFromList(Arrays.asList("a*b", "c,d", "e*f"), "*,"));
124    }
125    }