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

File ListPropertyTest.java

 

Code metrics

0
30
7
1
131
69
7
0.23
4.29
7
1

Classes

Class Line # Actions
ListPropertyTest 37 30 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 6 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;
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.test.jmock.AbstractComponentTestCase;
29   
30    import com.xpn.xwiki.web.Utils;
31   
32    /**
33    * Test list property.
34    *
35    * @version $Id: 0ceec52fb66fdd33663f0ff4414ceba36a6a3d79 $
36    */
 
37    public class ListPropertyTest extends AbstractComponentTestCase
38    {
39   
 
40  6 toggle @Before
41    public void configure() throws Exception
42    {
43  6 Utils.setComponentManager(getComponentManager());
44    }
45   
 
46  1 toggle @Test
47    public void dirtyFlagPropagation() throws Exception
48    {
49  1 ListProperty p = new ListProperty();
50   
51  1 p.setValueDirty(false);
52   
53  1 List<String> list = p.getList();
54   
55  1 list.add("foo");
56   
57  1 Assert.assertTrue(p.isValueDirty());
58   
59  1 p.setValueDirty(false);
60   
61  1 p.setList(null);
62   
63  1 Assert.assertTrue(p.isValueDirty());
64    }
65   
 
66  1 toggle @Test
67    public void cloneListProperty() throws Exception
68    {
69  1 ListProperty p = new ListProperty();
70   
71  1 List<String> pList = p.getList();
72   
73  1 p.setValueDirty(false);
74   
75  1 ListProperty clone = p.clone();
76   
77  1 List<String> cloneList = clone.getList();
78   
79  1 Assert.assertFalse(clone.isValueDirty());
80   
81  1 cloneList.add("foo");
82   
83  1 Assert.assertFalse(p.isValueDirty());
84  1 Assert.assertTrue(clone.isValueDirty());
85    }
86   
87    /**
88    * Tests that the value that is saved in the database for a list property is not XML-encoded.
89    */
 
90  1 toggle @Test
91    public void getTextValue()
92    {
93  1 ListProperty listProperty = new ListProperty();
94  1 listProperty.setValue(Arrays.asList("a<b>c", "1\"2'3", "x{y&z"));
95  1 Assert.assertEquals("a<b>c|1\"2'3|x{y&z", listProperty.getTextValue());
96    }
97   
98    /**
99    * Tests that {@link ListProperty#toText()} joins the values using the right separator, without XML-encoding the
100    * values.
101    */
 
102  1 toggle @Test
103    public void toText()
104    {
105  1 ListProperty listProperty = new ListProperty();
106  1 listProperty.setValue(Arrays.asList("c<b>a", "3\"2'1", "z{y&x"));
107  1 Assert.assertEquals("c<b>a|3\"2'1|z{y&x", listProperty.toText());
108    }
109   
110    /**
111    * Tests that {@link ListProperty#toFormString()} is XML-encoded.
112    */
 
113  1 toggle @Test
114    public void toFormString()
115    {
116  1 ListProperty listProperty = new ListProperty();
117  1 listProperty.setValue(Arrays.asList("o<n>e", "t\"w'o", "t{h&ree"));
118  1 Assert.assertEquals("o&#60;n&#62;e|t&#34;w&#39;o|t&#123;h&#38;ree", listProperty.toFormString());
119    }
120   
121    /**
122    * Tests that {@link ListProperty#toText()} properly joins values containing the separator itself.
123    */
 
124  1 toggle @Test
125    public void toTextValuesWithEscapedSeparators()
126    {
127  1 ListProperty listProperty = new ListProperty();
128  1 listProperty.setValue(Arrays.asList("a|b", "c|d", "e\\|f"));
129  1 Assert.assertEquals("a\\|b|c\\|d|e\\\\|f", listProperty.toText());
130    }
131    }