Source Code Cross Referenced for AbstractTestIterator.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.Iterator;
019:        import java.util.NoSuchElementException;
020:
021:        import org.apache.commons.collections.AbstractTestObject;
022:
023:        /**
024:         * Abstract class for testing the Iterator interface.
025:         * <p>
026:         * This class provides a framework for testing an implementation of Iterator.
027:         * Concrete subclasses must provide the iterator to be tested.
028:         * They must also specify certain details of how the iterator operates by
029:         * overriding the supportsXxx() methods if necessary.
030:         * 
031:         * @since Commons Collections 3.0
032:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
033:         * 
034:         * @author Morgan Delagrange
035:         * @author Stephen Colebourne
036:         */
037:        public abstract class AbstractTestIterator extends AbstractTestObject {
038:
039:            /**
040:             * JUnit constructor.
041:             * 
042:             * @param testName  the test class name
043:             */
044:            public AbstractTestIterator(String testName) {
045:                super (testName);
046:            }
047:
048:            //-----------------------------------------------------------------------
049:            /**
050:             * Implement this method to return an iterator over an empty collection.
051:             * 
052:             * @return an empty iterator
053:             */
054:            public abstract Iterator makeEmptyIterator();
055:
056:            /**
057:             * Implement this method to return an iterator over a collection with elements.
058:             * 
059:             * @return a full iterator
060:             */
061:            public abstract Iterator makeFullIterator();
062:
063:            /**
064:             * Implements the abstract superclass method to return the full iterator.
065:             * 
066:             * @return a full iterator
067:             */
068:            public Object makeObject() {
069:                return makeFullIterator();
070:            }
071:
072:            /**
073:             * Whether or not we are testing an iterator that can be empty.
074:             * Default is true.
075:             * 
076:             * @return true if Iterator can be empty
077:             */
078:            public boolean supportsEmptyIterator() {
079:                return true;
080:            }
081:
082:            /**
083:             * Whether or not we are testing an iterator that can contain elements.
084:             * Default is true.
085:             * 
086:             * @return true if Iterator can be full
087:             */
088:            public boolean supportsFullIterator() {
089:                return true;
090:            }
091:
092:            /**
093:             * Whether or not we are testing an iterator that supports remove().
094:             * Default is true.
095:             * 
096:             * @return true if Iterator supports remove
097:             */
098:            public boolean supportsRemove() {
099:                return true;
100:            }
101:
102:            /**
103:             * Allows subclasses to add complex cross verification
104:             */
105:            public void verify() {
106:                // do nothing
107:            }
108:
109:            //-----------------------------------------------------------------------
110:            /**
111:             * Test the empty iterator.
112:             */
113:            public void testEmptyIterator() {
114:                if (supportsEmptyIterator() == false) {
115:                    return;
116:                }
117:
118:                Iterator it = makeEmptyIterator();
119:
120:                // hasNext() should return false
121:                assertEquals(
122:                        "hasNext() should return false for empty iterators",
123:                        false, it.hasNext());
124:
125:                // next() should throw a NoSuchElementException
126:                try {
127:                    it.next();
128:                    fail("NoSuchElementException must be thrown when Iterator is exhausted");
129:                } catch (NoSuchElementException e) {
130:                }
131:                verify();
132:
133:                assertNotNull(it.toString());
134:            }
135:
136:            /**
137:             * Test normal iteration behaviour.
138:             */
139:            public void testFullIterator() {
140:                if (supportsFullIterator() == false) {
141:                    return;
142:                }
143:
144:                Iterator it = makeFullIterator();
145:
146:                // hasNext() must be true (ensure makeFullIterator is correct!)
147:                assertEquals(
148:                        "hasNext() should return true for at least one element",
149:                        true, it.hasNext());
150:
151:                // next() must not throw exception (ensure makeFullIterator is correct!)
152:                try {
153:                    it.next();
154:                } catch (NoSuchElementException e) {
155:                    fail("Full iterators must have at least one element");
156:                }
157:
158:                // iterate through
159:                while (it.hasNext()) {
160:                    it.next();
161:                    verify();
162:                }
163:
164:                // next() must throw NoSuchElementException now
165:                try {
166:                    it.next();
167:                    fail("NoSuchElementException must be thrown when Iterator is exhausted");
168:                } catch (NoSuchElementException e) {
169:                }
170:
171:                assertNotNull(it.toString());
172:            }
173:
174:            /**
175:             * Test remove behaviour.
176:             */
177:            public void testRemove() {
178:                Iterator it = makeFullIterator();
179:
180:                if (supportsRemove() == false) {
181:                    // check for UnsupportedOperationException if not supported
182:                    try {
183:                        it.remove();
184:                    } catch (UnsupportedOperationException ex) {
185:                    }
186:                    return;
187:                }
188:
189:                // should throw IllegalStateException before next() called
190:                try {
191:                    it.remove();
192:                    fail();
193:                } catch (IllegalStateException ex) {
194:                }
195:                verify();
196:
197:                // remove after next should be fine
198:                it.next();
199:                it.remove();
200:
201:                // should throw IllegalStateException for second remove()
202:                try {
203:                    it.remove();
204:                    fail();
205:                } catch (IllegalStateException ex) {
206:                }
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.