Source Code Cross Referenced for AbstractTestOrderedMapIterator.java in  » Library » Apache-common-Collections » org » apache » commons » collections » iterators » 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 » Library » Apache common Collections » org.apache.commons.collections.iterators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2004 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.apache.commons.collections.iterators;
017:
018:        import java.util.ArrayList;
019:        import java.util.HashSet;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Map;
023:        import java.util.NoSuchElementException;
024:        import java.util.Set;
025:
026:        import org.apache.commons.collections.OrderedMapIterator;
027:
028:        /**
029:         * Abstract class for testing the OrderedMapIterator interface.
030:         * <p>
031:         * This class provides a framework for testing an implementation of MapIterator.
032:         * Concrete subclasses must provide the list iterator to be tested.
033:         * They must also specify certain details of how the list iterator operates by
034:         * overriding the supportsXxx() methods if necessary.
035:         * 
036:         * @since Commons Collections 3.0
037:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
038:         * 
039:         * @author Stephen Colebourne
040:         */
041:        public abstract class AbstractTestOrderedMapIterator extends
042:                AbstractTestMapIterator {
043:
044:            /**
045:             * JUnit constructor.
046:             * 
047:             * @param testName  the test class name
048:             */
049:            public AbstractTestOrderedMapIterator(String testName) {
050:                super (testName);
051:            }
052:
053:            //-----------------------------------------------------------------------
054:            public final OrderedMapIterator makeEmptyOrderedMapIterator() {
055:                return (OrderedMapIterator) makeEmptyMapIterator();
056:            }
057:
058:            public final OrderedMapIterator makeFullOrderedMapIterator() {
059:                return (OrderedMapIterator) makeFullMapIterator();
060:            }
061:
062:            //-----------------------------------------------------------------------
063:            /**
064:             * Test that the empty list iterator contract is correct.
065:             */
066:            public void testEmptyMapIterator() {
067:                if (supportsEmptyIterator() == false) {
068:                    return;
069:                }
070:
071:                super .testEmptyMapIterator();
072:
073:                OrderedMapIterator it = makeEmptyOrderedMapIterator();
074:                Map map = getMap();
075:                assertEquals(false, it.hasPrevious());
076:                try {
077:                    it.previous();
078:                    fail();
079:                } catch (NoSuchElementException ex) {
080:                }
081:            }
082:
083:            //-----------------------------------------------------------------------
084:            /**
085:             * Test that the full list iterator contract is correct.
086:             */
087:            public void testFullMapIterator() {
088:                if (supportsFullIterator() == false) {
089:                    return;
090:                }
091:
092:                super .testFullMapIterator();
093:
094:                OrderedMapIterator it = makeFullOrderedMapIterator();
095:                Map map = getMap();
096:
097:                assertEquals(true, it.hasNext());
098:                assertEquals(false, it.hasPrevious());
099:                Set set = new HashSet();
100:                while (it.hasNext()) {
101:                    // getKey
102:                    Object key = it.next();
103:                    assertSame("it.next() should equals getKey()", key, it
104:                            .getKey());
105:                    assertTrue("Key must be in map", map.containsKey(key));
106:                    assertTrue("Key must be unique", set.add(key));
107:
108:                    // getValue
109:                    Object value = it.getValue();
110:                    if (isGetStructuralModify() == false) {
111:                        assertSame("Value must be mapped to key", map.get(key),
112:                                value);
113:                    }
114:                    assertTrue("Value must be in map", map.containsValue(value));
115:
116:                    assertEquals(true, it.hasPrevious());
117:
118:                    verify();
119:                }
120:                while (it.hasPrevious()) {
121:                    // getKey
122:                    Object key = it.previous();
123:                    assertSame("it.previous() should equals getKey()", key, it
124:                            .getKey());
125:                    assertTrue("Key must be in map", map.containsKey(key));
126:                    assertTrue("Key must be unique", set.remove(key));
127:
128:                    // getValue
129:                    Object value = it.getValue();
130:                    if (isGetStructuralModify() == false) {
131:                        assertSame("Value must be mapped to key", map.get(key),
132:                                value);
133:                    }
134:                    assertTrue("Value must be in map", map.containsValue(value));
135:
136:                    assertEquals(true, it.hasNext());
137:
138:                    verify();
139:                }
140:            }
141:
142:            //-----------------------------------------------------------------------
143:            /**
144:             * Test that the iterator order matches the keySet order.
145:             */
146:            public void testMapIteratorOrder() {
147:                if (supportsFullIterator() == false) {
148:                    return;
149:                }
150:
151:                OrderedMapIterator it = makeFullOrderedMapIterator();
152:                Map map = getMap();
153:
154:                assertEquals("keySet() not consistent", new ArrayList(map
155:                        .keySet()), new ArrayList(map.keySet()));
156:
157:                Iterator it2 = map.keySet().iterator();
158:                assertEquals(true, it.hasNext());
159:                assertEquals(true, it2.hasNext());
160:                List list = new ArrayList();
161:                while (it.hasNext()) {
162:                    Object key = it.next();
163:                    assertEquals(it2.next(), key);
164:                    list.add(key);
165:                }
166:                assertEquals(map.size(), list.size());
167:                while (it.hasPrevious()) {
168:                    Object key = it.previous();
169:                    assertEquals(list.get(list.size() - 1), key);
170:                    list.remove(list.size() - 1);
171:                }
172:                assertEquals(0, list.size());
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.