1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.security.authorization

File RightMapTest.java

 

Code metrics

6
30
9
1
113
76
13
0.43
3.33
9
1.44

Classes

Class Line # Actions
RightMapTest 31 30 0% 13 6
0.866666786.7%
 

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.security.authorization;
21   
22    import java.util.Map;
23    import com.google.common.collect.testing.MapInterfaceTest;
24   
25    /**
26    * Test Map interface of RightMap using guava test library.
27    *
28    * @version $Id: ab572483d9bea42adf1424b3efed07ebda8aa915 $
29    * @since 4.0M2
30    */
 
31    public class RightMapTest extends MapInterfaceTest<Right, Object>
32    {
33    private Map<Right, Object> populatedMap;
34    private Object valueNotInPopulatedMaplatedMap;
35   
 
36  112 toggle public RightMapTest()
37    {
38  112 super(false, true, true, true, true, true);
39    }
40   
 
41  11 toggle @Override
42    protected Map<Right, Object> makeEmptyMap()
43    {
44  11 return new RightMap<Object>();
45    }
46   
 
47  236 toggle private Object getNewValue() {
48  236 return new Object() {
 
49  39 toggle @Override
50    public int hashCode()
51    {
52  39 throw new UnsupportedOperationException();
53    }
54   
 
55  0 toggle @Override
56    public String toString()
57    {
58  0 return "[Object@" + Integer.toHexString(super.hashCode()) + "]";
59    }
60    };
61    }
62   
 
63  47 toggle @Override
64    protected Map<Right, Object> makePopulatedMap()
65    {
66  47 if (populatedMap == null) {
67  44 populatedMap = new RightMap<Object>();
68  44 populatedMap.put(Right.VIEW, getNewValue());
69  44 populatedMap.put(Right.EDIT, getNewValue());
70  44 populatedMap.put(Right.COMMENT, getNewValue());
71  44 populatedMap.put(Right.DELETE, getNewValue());
72  44 populatedMap.put(Right.ADMIN, getNewValue());
73    }
74  47 Map<Right, Object> newMap = new RightMap<Object>();
75  47 for (Map.Entry<Right, Object> entry : populatedMap.entrySet()) {
76  235 newMap.put(entry.getKey(), entry.getValue());
77    }
78  47 return newMap;
79    }
80   
 
81  10 toggle @Override
82    protected Right getKeyNotInPopulatedMap()
83    {
84  10 return Right.PROGRAM;
85    }
86   
 
87  16 toggle @Override
88    protected Object getValueNotInPopulatedMap()
89    {
90  16 if (valueNotInPopulatedMaplatedMap == null) {
91  16 valueNotInPopulatedMaplatedMap = getNewValue();
92    }
93  16 return valueNotInPopulatedMaplatedMap;
94    }
95   
 
96  1 toggle public void testEqualsForLargerMap() {
97  1 if (!supportsPut) {
98  0 return;
99    }
100   
101  1 final Map<Right, Object> map;
102  1 final Map<Right, Object> largerMap;
103  1 try {
104  1 map = makePopulatedMap();
105  1 largerMap = makePopulatedMap();
106  1 largerMap.put(getKeyNotInPopulatedMap(), getValueNotInPopulatedMap());
107    } catch (UnsupportedOperationException e) {
108  0 return;
109    }
110   
111  1 assertFalse(map.equals(largerMap));
112    }
113    }