Source Code Cross Referenced for TestRegistry.java in  » Test-Coverage » Quilt » org » quilt » reg » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » Quilt » org.quilt.reg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* TestRegistry.java */
002:
003:        package org.quilt.reg;
004:
005:        import junit.framework.*;
006:
007:        public class TestRegistry extends TestCase {
008:
009:            private Registry reg = null;
010:
011:            public TestRegistry(String name) {
012:                super (name);
013:            }
014:
015:            String salutation[] = { "hello", "there" };
016:
017:            String key1[] = { "Quilt", "ARG0" };
018:            String key2[] = { "Elvis", "lives" };
019:            String key3[] = { "One plus ", "one" };
020:            String key4[] = { "Elvis", "wombat" };
021:            String key5[] = { "Elvis", "heart-throb" };
022:            String obj1 = "froggy boy";
023:            String obj2 = "Topeka, Kansas";
024:            Integer obj3 = new Integer(3);
025:            Boolean obj4 = new Boolean(true);
026:            Float obj5 = new Float((float) 5.47);
027:
028:            public void setUp() {
029:                reg = new Registry();
030:                reg.clear();
031:            }
032:
033:            public void testEmpty() {
034:                assertEquals("Empty registry has items in it", 0, reg.size());
035:                assertNull("Retrieved item from empty registry", reg
036:                        .get(salutation));
037:                assertTrue("Empty registry is not empty", reg.isEmpty());
038:            }
039:
040:            public void testSimple() {
041:                assertNull("Put with no previous value - ", reg.put(key1, obj1));
042:                assertEquals(1, reg.size());
043:                assertTrue(reg.containsKey(key1));
044:                assertNull("Put with no previous value - ", reg.put(key2, obj2));
045:                assertEquals(2, reg.size());
046:                assertTrue(reg.containsKey(key2));
047:                assertNull("Put with no previous value - ", reg.put(key3, obj3));
048:                assertEquals(3, reg.size());
049:                assertTrue(reg.containsKey(key3));
050:
051:                // make sure all three are present and have correct values
052:                assertEquals("'Quilt' get returns wrong value", obj1, reg
053:                        .get(key1));
054:                assertEquals("'Elvis' get returns wrong value", obj2, reg
055:                        .get(key2));
056:                assertEquals("'One plus' get returns wrong value", obj3, reg
057:                        .get(key3));
058:
059:                // overwrite, check return value is previous value
060:                assertEquals("Put did not return previous value", obj1, reg
061:                        .put(key1, obj2));
062:                assertEquals(3, reg.size());
063:                assertEquals("Put did not return previous value", obj2, reg
064:                        .put(key2, obj3));
065:                assertEquals(3, reg.size());
066:                assertEquals("Put did not return previous value", obj3, reg
067:                        .put(key3, obj1));
068:                assertEquals(3, reg.size());
069:
070:                // check value returned on deletion is stored value
071:                assertEquals("remove did not return value stored", obj2, reg
072:                        .remove(key1));
073:                assertTrue("Item deleted but still present", !reg
074:                        .containsKey(key1));
075:                assertEquals(2, reg.size());
076:
077:                assertEquals("remove did not return value stored", obj3, reg
078:                        .remove(key2));
079:                assertTrue("Item deleted but still present", !reg
080:                        .containsKey(key2));
081:                assertEquals(1, reg.size());
082:
083:                assertEquals("remove did not return value stored", obj1, reg
084:                        .remove(key3));
085:                assertTrue("Item deleted but still present", !reg
086:                        .containsKey(key3));
087:                assertEquals(0, reg.size());
088:                assertTrue("Empty registry is not empty", reg.isEmpty());
089:            }
090:
091:            public void testBoolean() {
092:                // put some random stuff in the registry ...
093:                assertNull("Put with no previous value - ", reg.put(key1, obj1));
094:                assertEquals(1, reg.size());
095:                assertTrue(reg.containsKey(key1));
096:                // first Elvis 
097:                assertNull("Put with no previous value - ", reg.put(key2, obj2));
098:                assertEquals(2, reg.size());
099:                assertTrue(reg.containsKey(key2));
100:                assertNull("Put with no previous value - ", reg.put(key3, obj3));
101:                assertEquals(3, reg.size());
102:                assertTrue(reg.containsKey(key3));
103:
104:                Boolean t = new Boolean(true);
105:                Boolean f = new Boolean(false);
106:                String tKey[] = { "the", "truth" };
107:                String fKey[] = { "a", "falsehood" };
108:                assertNull("Put with no previous value - ", reg.put(tKey, t));
109:                assertEquals(4, reg.size());
110:                assertTrue("No truth in the database", reg.containsKey(tKey));
111:                assertNull("Put with no previous value - ", reg.put(fKey, f));
112:                assertEquals(5, reg.size());
113:                assertTrue("No lies in the database", reg.containsKey(fKey));
114:
115:                assertEquals("Can't get truth out of the registry", t, reg
116:                        .get(tKey));
117:                assertEquals("Can't get lies out of the registry", f, reg
118:                        .get(fKey));
119:
120:                assertTrue(t.booleanValue());
121:                assertTrue(((Boolean) reg.get(tKey)).booleanValue());
122:                assertTrue(!f.booleanValue());
123:                assertTrue(!((Boolean) reg.get(fKey)).booleanValue());
124:            }
125:
126:            public void testPartialOverlap() {
127:                assertNull("Put with no previous value - ", reg.put(key1, obj1));
128:                assertEquals(1, reg.size());
129:                assertTrue(reg.containsKey(key1));
130:                // Elvis/lives --> Topeka, Kansas
131:                assertNull("Put with no previous value - ", reg.put(key2, obj2));
132:                assertEquals(2, reg.size());
133:                assertTrue(reg.containsKey(key2));
134:                assertNull("Put with no previous value - ", reg.put(key3, obj3));
135:                assertEquals(3, reg.size());
136:                assertTrue(reg.containsKey(key3));
137:
138:                // the next two have the same value (Elvis) in key[0]
139:                // Elvis/wombat --> Boolean(true)
140:                assertNull("Put with no previous value - ", reg.put(key4, obj4));
141:                assertEquals(4, reg.size());
142:                assertTrue(reg.containsKey(key4));
143:                // Elvis/heart-throb --> Float(5.47)
144:                assertNull("Put with no previous value - ", reg.put(key5, obj5));
145:                assertEquals(5, reg.size());
146:                assertTrue(reg.containsKey(key5));
147:
148:                // overwrite, check return value is previous value
149:                assertEquals("Put did not return previous value", obj1, reg
150:                        .put(key1, obj2));
151:                assertEquals(5, reg.size());
152:                assertEquals("Put did not return previous value", obj2, reg
153:                        .put(key2, obj3));
154:                assertEquals(5, reg.size());
155:                assertEquals("Put did not return previous value", obj3, reg
156:                        .put(key3, obj1));
157:                assertEquals(5, reg.size());
158:
159:                // Elvis/wombat returns Integer(3) 
160:                assertEquals("Elvis/wombat put did not return previous value",
161:                        obj4, reg.put(key4, obj5));
162:                assertEquals(5, reg.size());
163:                assertEquals(
164:                        "Elvis/heart-throb put did not return previous value",
165:                        obj5, reg.put(key5, obj4));
166:                assertEquals(5, reg.size());
167:
168:                // check value returned on deletion is stored value
169:                // first Elvis ...
170:                assertEquals("remove did not return value stored", obj4, reg
171:                        .remove(key5));
172:                assertTrue("Item deleted but still present", !reg
173:                        .containsKey(key5));
174:                assertEquals(4, reg.size());
175:                assertEquals("remove did not return value stored", obj5, reg
176:                        .remove(key4));
177:                assertTrue("Item deleted but still present", !reg
178:                        .containsKey(key4));
179:                assertEquals(3, reg.size());
180:                // then the rest
181:                assertEquals("remove did not return value stored", obj2, reg
182:                        .remove(key1));
183:                assertTrue("Item deleted but still present", !reg
184:                        .containsKey(key1));
185:                assertEquals(2, reg.size());
186:
187:                assertEquals("remove did not return value stored", obj3, reg
188:                        .remove(key2));
189:                assertTrue("Item deleted but still present", !reg
190:                        .containsKey(key2));
191:                assertEquals(1, reg.size());
192:
193:                assertEquals("remove did not return value stored", obj1, reg
194:                        .remove(key3));
195:                assertTrue("Item deleted but still present", !reg
196:                        .containsKey(key3));
197:                assertEquals(0, reg.size());
198:                assertTrue("Empty registry is not empty", reg.isEmpty()); // GEEP
199:            }
200:
201:            public void testElvis() {
202:                // keys{2,4,5} have "Elvis" as key[0]
203:
204:                // Elvis/lives --> Topeka, Kansas
205:                assertNull("Put with no previous value - ", reg.put(key2, obj2));
206:                assertEquals(1, reg.size());
207:                assertTrue(reg.containsKey(key2));
208:
209:                // Elvis/wombat --> Boolean(true)
210:                assertNull("Put with no previous value - ", reg.put(key4, obj4));
211:                assertEquals(2, reg.size());
212:                assertTrue(reg.containsKey(key4));
213:
214:                // Elvis/heart-throb --> Float(5.47)
215:                assertNull("Put with no previous value - ", reg.put(key5, obj5));
216:                assertEquals(3, reg.size());
217:                assertTrue(reg.containsKey(key5));
218:
219:                // make sure all three are present and have correct values
220:                assertEquals("Elvis/lives get error", obj2, reg.get(key2));
221:                assertEquals("Elvis/wombat get error", obj4, reg.get(key4));
222:                assertEquals("Elvis/heart-throb get error", obj5, reg.get(key5));
223:
224:                // overwrite, check return value is previous value
225:                assertEquals("Put did not return previous value", obj2, reg
226:                        .put(key2, obj4));
227:                assertEquals(3, reg.size());
228:                assertEquals("Put did not return previous value", obj4, reg
229:                        .put(key4, obj5));
230:                assertEquals(3, reg.size());
231:                assertEquals("Put did not return previous value", obj5, reg
232:                        .put(key5, obj2));
233:                assertEquals(3, reg.size());
234:
235:                // check value returned on deletion is stored value
236:                assertEquals("remove did not return value stored", obj4, reg
237:                        .remove(key2));
238:                assertTrue("Item deleted but still present", !reg
239:                        .containsKey(key2));
240:                assertEquals(2, reg.size());
241:
242:                assertEquals("remove did not return value stored", obj5, reg
243:                        .remove(key4));
244:                assertTrue("Item deleted but still present", !reg
245:                        .containsKey(key4));
246:                assertEquals(1, reg.size());
247:
248:                assertEquals("remove did not return value stored", obj2, reg
249:                        .remove(key5));
250:                assertTrue("Item deleted but still present", !reg
251:                        .containsKey(key5));
252:                assertEquals(0, reg.size());
253:                assertTrue("Empty registry is not empty", reg.isEmpty()); // GEEP
254:            }
255:
256:            public void testRG2() {
257:                // duplicating bug found in the field
258:                String keys1[] = { "rg2", "msg" };
259:                Boolean val1 = new Boolean(true);
260:                String keys2[] = { "rg2", "test" };
261:                String val2 = "hope this works";
262:
263:                assertEquals(0, reg.size());
264:
265:                assertNull("Put with no previous value - ", reg
266:                        .put(keys1, val1));
267:                assertEquals(1, reg.size());
268:                assertTrue(reg.containsKey(keys1));
269:
270:                assertNull("Put with no previous value - ", reg
271:                        .put(keys2, val2));
272:                assertEquals(2, reg.size());
273:                assertTrue(reg.containsKey(keys2));
274:
275:                assertEquals("rg2/msg get error", val1, reg.get(keys1));
276:                assertEquals("rg2/test get error", val2, reg.get(keys2));
277:            }
278:
279:            public void testExceptions() {
280:                // database is empty
281:                try {
282:                    reg.get(null);
283:                    fail("get with null key did not throw exception");
284:                } catch (IllegalArgumentException e) {
285:                }
286:
287:                try {
288:                    reg.put(key1, obj1);
289:                    reg.put(null, obj2);
290:                    fail("put with null key did not throw exception");
291:                } catch (IllegalArgumentException e) {
292:                    assertEquals(1, reg.size());
293:                }
294:                try {
295:                    reg.put(key2, obj2);
296:                    reg.containsKey(null);
297:                    fail("containsKey with null key did not throw exception");
298:                } catch (IllegalArgumentException e) {
299:                    assertEquals(2, reg.size());
300:                }
301:                try {
302:                    reg.put(key3, obj3);
303:                    reg.remove(null);
304:                    fail("remove with null key did not throw exception");
305:                } catch (IllegalArgumentException e) {
306:                    assertEquals(3, reg.size());
307:                }
308:            }
309:            // COMING ATTRACTIONS:
310:            //
311:            // test sequential operations
312:            //
313:            // test set-wise operations
314:            //
315:            // test sub-map operations
316:
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.