Source Code Cross Referenced for AbstractMapTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » util » 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 » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.luni.tests.java.util;
019:
020:        import java.util.AbstractMap;
021:        import java.util.AbstractSet;
022:        import java.util.Collections;
023:        import java.util.Comparator;
024:        import java.util.HashMap;
025:        import java.util.HashSet;
026:        import java.util.Hashtable;
027:        import java.util.IdentityHashMap;
028:        import java.util.Iterator;
029:        import java.util.LinkedHashMap;
030:        import java.util.Map;
031:        import java.util.Set;
032:        import java.util.TreeMap;
033:        import java.util.Vector;
034:        import java.util.WeakHashMap;
035:
036:        public class AbstractMapTest extends junit.framework.TestCase {
037:
038:            static final String specialKey = "specialKey".intern();
039:
040:            static final String specialValue = "specialValue".intern();
041:
042:            // The impl of MyMap is not realistic, but serves to create a type
043:            // that uses the default remove behavior.
044:            class MyMap extends AbstractMap {
045:                final Set mySet = new HashSet(1);
046:
047:                MyMap() {
048:                    mySet.add(new Map.Entry() {
049:                        public Object getKey() {
050:                            return specialKey;
051:                        }
052:
053:                        public Object getValue() {
054:                            return specialValue;
055:                        }
056:
057:                        public Object setValue(Object object) {
058:                            return null;
059:                        }
060:                    });
061:                }
062:
063:                public Object put(Object key, Object value) {
064:                    return null;
065:                }
066:
067:                public Set entrySet() {
068:                    return mySet;
069:                }
070:            }
071:
072:            /**
073:             * @tests java.util.AbstractMap#keySet()
074:             */
075:            public void test_keySet() {
076:                AbstractMap map1 = new HashMap(0);
077:                assertSame("HashMap(0)", map1.keySet(), map1.keySet());
078:
079:                AbstractMap map2 = new HashMap(10);
080:                assertSame("HashMap(10)", map2.keySet(), map2.keySet());
081:
082:                Map map3 = Collections.EMPTY_MAP;
083:                assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
084:
085:                AbstractMap map4 = new IdentityHashMap(1);
086:                assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
087:
088:                AbstractMap map5 = new LinkedHashMap(122);
089:                assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
090:
091:                AbstractMap map6 = new TreeMap();
092:                assertSame("TreeMap", map6.keySet(), map6.keySet());
093:
094:                AbstractMap map7 = new WeakHashMap();
095:                assertSame("WeakHashMap", map7.keySet(), map7.keySet());
096:            }
097:
098:            /**
099:             * @tests java.util.AbstractMap#remove(java.lang.Object)
100:             */
101:            public void test_removeLjava_lang_Object() {
102:                Object key = new Object();
103:                Object value = new Object();
104:
105:                AbstractMap map1 = new HashMap(0);
106:                map1.put("key", value);
107:                assertSame("HashMap(0)", map1.remove("key"), value);
108:
109:                AbstractMap map4 = new IdentityHashMap(1);
110:                map4.put(key, value);
111:                assertSame("IdentityHashMap", map4.remove(key), value);
112:
113:                AbstractMap map5 = new LinkedHashMap(122);
114:                map5.put(key, value);
115:                assertSame("LinkedHashMap", map5.remove(key), value);
116:
117:                AbstractMap map6 = new TreeMap(new Comparator() {
118:                    // Bogus comparator
119:                    public int compare(Object object1, Object object2) {
120:                        return 0;
121:                    }
122:                });
123:                map6.put(key, value);
124:                assertSame("TreeMap", map6.remove(key), value);
125:
126:                AbstractMap map7 = new WeakHashMap();
127:                map7.put(key, value);
128:                assertSame("WeakHashMap", map7.remove(key), value);
129:
130:                AbstractMap aSpecialMap = new MyMap();
131:                aSpecialMap.put(specialKey, specialValue);
132:                Object valueOut = aSpecialMap.remove(specialKey);
133:                assertSame("MyMap", valueOut, specialValue);
134:            }
135:
136:            /**
137:             * @tests java.util.AbstractMap#values()
138:             */
139:            public void test_values() {
140:                AbstractMap map1 = new HashMap(0);
141:                assertSame("HashMap(0)", map1.values(), map1.values());
142:
143:                AbstractMap map2 = new HashMap(10);
144:                assertSame("HashMap(10)", map2.values(), map2.values());
145:
146:                Map map3 = Collections.EMPTY_MAP;
147:                assertSame("EMPTY_MAP", map3.values(), map3.values());
148:
149:                AbstractMap map4 = new IdentityHashMap(1);
150:                assertSame("IdentityHashMap", map4.values(), map4.values());
151:
152:                AbstractMap map5 = new LinkedHashMap(122);
153:                assertSame("IdentityHashMap", map5.values(), map5.values());
154:
155:                AbstractMap map6 = new TreeMap();
156:                assertSame("TreeMap", map6.values(), map6.values());
157:
158:                AbstractMap map7 = new WeakHashMap();
159:                assertSame("WeakHashMap", map7.values(), map7.values());
160:            }
161:
162:            /**
163:             * @tests java.util.AbstractMap#clone()
164:             */
165:            public void test_clone() {
166:                class MyMap extends AbstractMap implements  Cloneable {
167:                    private Map map = new HashMap();
168:
169:                    public Set entrySet() {
170:                        return map.entrySet();
171:                    }
172:
173:                    public Object put(Object key, Object value) {
174:                        return map.put(key, value);
175:                    }
176:
177:                    public Map getMap() {
178:                        return map;
179:                    }
180:
181:                    public Object clone() {
182:                        try {
183:                            return super .clone();
184:                        } catch (CloneNotSupportedException e) {
185:                            return null;
186:                        }
187:                    }
188:                }
189:                ;
190:                MyMap map = new MyMap();
191:                map.put("one", "1");
192:                Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
193:                assertTrue("entry not added", entry.getKey() == "one"
194:                        && entry.getValue() == "1");
195:                MyMap mapClone = (MyMap) map.clone();
196:                assertTrue("clone not shallow", map.getMap() == mapClone
197:                        .getMap());
198:            }
199:
200:            public class AMT extends AbstractMap {
201:
202:                // Very crude AbstractMap implementation
203:                Vector values = new Vector();
204:
205:                Vector keys = new Vector();
206:
207:                public Set entrySet() {
208:                    return new AbstractSet() {
209:                        public Iterator iterator() {
210:                            return new Iterator() {
211:                                int index = 0;
212:
213:                                public boolean hasNext() {
214:                                    return index < values.size();
215:                                }
216:
217:                                public Object next() {
218:                                    if (index < values.size()) {
219:                                        Map.Entry me = new Map.Entry() {
220:                                            Object v = values.elementAt(index);
221:
222:                                            Object k = keys.elementAt(index);
223:
224:                                            public Object getKey() {
225:                                                return k;
226:                                            }
227:
228:                                            public Object getValue() {
229:                                                return v;
230:                                            }
231:
232:                                            public Object setValue(Object value) {
233:                                                return null;
234:                                            }
235:                                        };
236:                                        index++;
237:                                        return me;
238:                                    }
239:                                    return null;
240:                                }
241:
242:                                public void remove() {
243:                                }
244:                            };
245:                        }
246:
247:                        public int size() {
248:                            return values.size();
249:                        }
250:                    };
251:                }
252:
253:                public Object put(Object k, Object v) {
254:                    keys.add(k);
255:                    values.add(v);
256:                    return v;
257:                }
258:            }
259:
260:            /**
261:             * @tests {@link java.util.AbstractMap#putAll(Map)}
262:             */
263:            public void test_putAllLMap() {
264:                Hashtable ht = new Hashtable();
265:                AMT amt = new AMT();
266:                ht.put("this", "that");
267:                amt.putAll(ht);
268:                assertEquals("Should be equal", amt, ht);
269:            }
270:
271:            protected void setUp() {
272:            }
273:
274:            protected void tearDown() {
275:            }
276:        }
www.__j___a__v_a__2_s___._c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.