1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.core.statement.naturallanguage; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.List; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import junit.framework.Assert; |
24 |
|
|
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Test; |
27 |
|
import org.kuali.student.core.exceptions.OperationFailedException; |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (54) |
Complexity: 8 |
Complexity Density: 0.17 |
|
29 |
|
public class ContextRegistryTest { |
30 |
|
|
31 |
|
private ContextRegistry<DeveloperContext> emptyRegistry; |
32 |
|
private ContextRegistry<DeveloperContext> fullRegistry; |
33 |
|
|
34 |
|
private DeveloperContext context1 = new DeveloperContext(); |
35 |
|
private DeveloperContext context2 = new DeveloperContext(); |
36 |
|
private DeveloperContext context3 = new DeveloperContext(); |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.33 |
|
38 |
|
private static class DeveloperContext implements Context<String> { |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
40 |
0
|
public Map<String, Object> createContextMap(String id) throws OperationFailedException {... |
41 |
0
|
Map<String, Object> contextMap = new HashMap<String, Object>(); |
42 |
0
|
contextMap.put(id, id); |
43 |
|
|
44 |
0
|
return contextMap; |
45 |
|
} |
46 |
|
} |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
48 |
7
|
@Before... |
49 |
|
public void setUp() throws Exception { |
50 |
7
|
emptyRegistry = new ContextRegistry<DeveloperContext>(); |
51 |
|
|
52 |
7
|
Map<String, List<DeveloperContext>> map = new HashMap<String, List<DeveloperContext>>(); |
53 |
7
|
List<DeveloperContext> list1 = new ArrayList<DeveloperContext>(); |
54 |
7
|
list1.add(context1); |
55 |
7
|
list1.add(context2); |
56 |
7
|
map.put("c1", list1); |
57 |
7
|
List<DeveloperContext> list2 = new ArrayList<DeveloperContext>(); |
58 |
7
|
list2.add(context3); |
59 |
7
|
map.put("c2", list2); |
60 |
|
|
61 |
7
|
fullRegistry = new ContextRegistry<DeveloperContext>(map); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
64 |
1
|
@Test... |
65 |
|
public void testAdd() throws Exception { |
66 |
1
|
List<DeveloperContext> list = new ArrayList<DeveloperContext>(); |
67 |
1
|
DeveloperContext context = new DeveloperContext(); |
68 |
1
|
list.add(context); |
69 |
1
|
emptyRegistry.add("123", context); |
70 |
|
|
71 |
1
|
Assert.assertNotNull(emptyRegistry.get("123")); |
72 |
1
|
Assert.assertEquals(1, emptyRegistry.get("123").size()); |
73 |
1
|
Assert.assertEquals(context, emptyRegistry.get("123").get(0)); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
76 |
1
|
@Test... |
77 |
|
public void testGet() throws Exception { |
78 |
1
|
List<DeveloperContext> list = new ArrayList<DeveloperContext>(); |
79 |
1
|
DeveloperContext context = new DeveloperContext(); |
80 |
1
|
list.add(context); |
81 |
1
|
emptyRegistry.add("123", context); |
82 |
|
|
83 |
1
|
Assert.assertNotNull(emptyRegistry.get("123")); |
84 |
1
|
Assert.assertEquals(1, emptyRegistry.get("123").size()); |
85 |
1
|
Assert.assertEquals(context, emptyRegistry.get("123").get(0)); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1
PASS
|
|
88 |
1
|
@Test... |
89 |
|
public void testGet_MultipleContext() throws Exception { |
90 |
1
|
Assert.assertEquals(2, fullRegistry.size()); |
91 |
1
|
Assert.assertNotNull(fullRegistry.get("c1")); |
92 |
1
|
Assert.assertEquals(2, fullRegistry.get("c1").size()); |
93 |
1
|
Assert.assertEquals(context1, fullRegistry.get("c1").get(0)); |
94 |
1
|
Assert.assertEquals(context2, fullRegistry.get("c1").get(1)); |
95 |
1
|
Assert.assertNotNull(fullRegistry.get("c2")); |
96 |
1
|
Assert.assertEquals(1, fullRegistry.get("c2").size()); |
97 |
1
|
Assert.assertEquals(context3, fullRegistry.get("c2").get(0)); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
100 |
1
|
@Test... |
101 |
|
public void testContainsKey() throws Exception { |
102 |
1
|
DeveloperContext context = new DeveloperContext(); |
103 |
1
|
emptyRegistry.add("123", context); |
104 |
|
|
105 |
1
|
Assert.assertTrue(emptyRegistry.containsKey("123")); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1
PASS
|
|
108 |
1
|
@Test... |
109 |
|
public void testContainsKey_MultipleContext() throws Exception { |
110 |
1
|
Assert.assertTrue(fullRegistry.containsKey("c1")); |
111 |
1
|
Assert.assertTrue(fullRegistry.containsKey("c2")); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
114 |
1
|
@Test... |
115 |
|
public void testRemove() throws Exception { |
116 |
1
|
DeveloperContext context = new DeveloperContext(); |
117 |
1
|
emptyRegistry.add("123", context); |
118 |
|
|
119 |
1
|
Assert.assertNotNull(emptyRegistry.get("123")); |
120 |
1
|
emptyRegistry.remove("123"); |
121 |
1
|
Assert.assertFalse(emptyRegistry.containsKey("123")); |
122 |
1
|
Assert.assertNull(emptyRegistry.get("123")); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
125 |
1
|
@Test... |
126 |
|
public void testRemove_MultipleContext() throws Exception { |
127 |
1
|
fullRegistry.remove("c1"); |
128 |
1
|
Assert.assertFalse(fullRegistry.containsKey("c1")); |
129 |
1
|
Assert.assertNull(fullRegistry.get("c1")); |
130 |
|
} |
131 |
|
} |