Clover Coverage Report - Kuali Student 1.1 (Aggregated)
Coverage timestamp: Sun Mar 6 2011 20:32:39 EST
49   131   9   5.44
0   93   0.18   4.5
9     1  
2    
 
  ContextRegistryTest       Line # 29 46 0% 8 0 100% 1.0
  ContextRegistryTest.DeveloperContext       Line # 38 3 0% 1 4 0% 0.0
 
  (7)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
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   
 
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   
 
38    private static class DeveloperContext implements Context<String> {
39   
 
40  0 toggle 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   
 
48  7 toggle @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   
 
64  1 toggle @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   
 
76  1 toggle @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   
 
88  1 toggle @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  1 toggle @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   
 
108  1 toggle @Test
109    public void testContainsKey_MultipleContext() throws Exception {
110  1 Assert.assertTrue(fullRegistry.containsKey("c1"));
111  1 Assert.assertTrue(fullRegistry.containsKey("c2"));
112    }
113   
 
114  1 toggle @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   
 
125  1 toggle @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    }