1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.security.authorization; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
import com.google.common.collect.testing.MapInterfaceTest; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
@version |
29 |
|
@since |
30 |
|
|
|
|
| 86.7% |
Uncovered Elements: 6 (45) |
Complexity: 13 |
Complexity Density: 0.43 |
|
31 |
|
public class RightMapTest extends MapInterfaceTest<Right, Object> |
32 |
|
{ |
33 |
|
private Map<Right, Object> populatedMap; |
34 |
|
private Object valueNotInPopulatedMaplatedMap; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
36 |
56 |
public RightMapTest()... |
37 |
|
{ |
38 |
56 |
super(false, true, true, true, true, true); |
39 |
|
} |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
41 |
11 |
@Override... |
42 |
|
protected Map<Right, Object> makeEmptyMap() |
43 |
|
{ |
44 |
11 |
return new RightMap<Object>(); |
45 |
|
} |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
236 |
private Object getNewValue() {... |
48 |
236 |
return new Object() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
39 |
@Override... |
50 |
|
public int hashCode() |
51 |
|
{ |
52 |
39 |
throw new UnsupportedOperationException(); |
53 |
|
} |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0 |
@Override... |
56 |
|
public String toString() |
57 |
|
{ |
58 |
0 |
return "[Object@" + Integer.toHexString(super.hashCode()) + "]"; |
59 |
|
} |
60 |
|
}; |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
63 |
47 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
10 |
@Override... |
82 |
|
protected Right getKeyNotInPopulatedMap() |
83 |
|
{ |
84 |
10 |
return Right.PROGRAM; |
85 |
|
} |
86 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
87 |
16 |
@Override... |
88 |
|
protected Object getValueNotInPopulatedMap() |
89 |
|
{ |
90 |
16 |
if (valueNotInPopulatedMaplatedMap == null) { |
91 |
16 |
valueNotInPopulatedMaplatedMap = getNewValue(); |
92 |
|
} |
93 |
16 |
return valueNotInPopulatedMaplatedMap; |
94 |
|
} |
95 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
1PASS
|
|
96 |
1 |
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 |
|
} |