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

File DefaultScriptSafeProviderTest.java

 

Code metrics

0
24
3
1
98
62
3
0.12
8
3
1

Classes

Class Line # Actions
DefaultScriptSafeProviderTest 41 24 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 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.script.internal.safe;
21   
22    import java.util.Arrays;
23    import java.util.Collection;
24    import java.util.LinkedHashMap;
25    import java.util.LinkedHashSet;
26    import java.util.List;
27    import java.util.Map;
28    import java.util.Set;
29   
30    import org.junit.Assert;
31    import org.junit.Rule;
32    import org.junit.Test;
33    import org.xwiki.script.internal.safe.CollectionScriptSafeProvider;
34    import org.xwiki.script.internal.safe.DefaultScriptSafeProvider;
35    import org.xwiki.script.internal.safe.MapScriptSafeProvider;
36    import org.xwiki.script.internal.safe.ScriptSafeProvider;
37    import org.xwiki.test.annotation.ComponentList;
38    import org.xwiki.test.mockito.MockitoComponentMockingRule;
39   
40    @ComponentList({ CollectionScriptSafeProvider.class, MapScriptSafeProvider.class })
 
41    public class DefaultScriptSafeProviderTest
42    {
43    @Rule
44    public MockitoComponentMockingRule<ScriptSafeProvider> mocker =
45    new MockitoComponentMockingRule<ScriptSafeProvider>(DefaultScriptSafeProvider.class);
46   
 
47  1 toggle @Test
48    public void testGetWithNoProvider() throws Exception
49    {
50  1 Object safe = "";
51   
52  1 Assert.assertSame(safe, this.mocker.getComponentUnderTest().get(safe));
53    }
54   
 
55  1 toggle @SuppressWarnings({ "rawtypes", "unchecked" })
56    @Test
57    public void testGetCollection() throws Exception
58    {
59    // List
60   
61  1 Collection unsafe = Arrays.asList("1", "2");
62  1 Collection safe = (Collection) this.mocker.getComponentUnderTest().get(unsafe);
63   
64  1 Assert.assertNotSame(unsafe, safe);
65  1 Assert.assertTrue(safe instanceof List);
66  1 Assert.assertEquals(unsafe, safe);
67   
68    // Set
69   
70  1 unsafe = new LinkedHashSet(Arrays.asList("1", "2", "3", "4", "5"));
71  1 safe = (Collection) this.mocker.getComponentUnderTest().get(unsafe);
72   
73  1 Assert.assertNotSame(unsafe, safe);
74  1 Assert.assertTrue(safe instanceof Set);
75  1 Assert.assertEquals(unsafe, safe);
76    // Make sure order is kept
77  1 Assert.assertEquals(unsafe.toString(), safe.toString());
78    }
79   
 
80  1 toggle @SuppressWarnings({ "rawtypes", "unchecked", "cast" })
81    @Test
82    public void testGetMap() throws Exception
83    {
84  1 Map unsafe = new LinkedHashMap(5);
85  1 unsafe.put("1", "1");
86  1 unsafe.put("2", "2");
87  1 unsafe.put("3", "3");
88  1 unsafe.put("4", "4");
89  1 unsafe.put("5", "5");
90  1 Map safe = (Map) this.mocker.getComponentUnderTest().get(unsafe);
91   
92  1 Assert.assertNotSame(unsafe, safe);
93  1 Assert.assertTrue(safe instanceof Map);
94  1 Assert.assertEquals(unsafe, safe);
95    // Make sure order is kept
96  1 Assert.assertEquals(unsafe.toString(), safe.toString());
97    }
98    }