Source Code Cross Referenced for TestArrayIterator2.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 junit.framework.Test;
022:        import junit.framework.TestSuite;
023:
024:        /**
025:         * Tests the ArrayIterator with primitive type arrays.
026:         * 
027:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
028:         * 
029:         * @author Morgan Delagrange
030:         * @author James Strachan
031:         */
032:        public class TestArrayIterator2 extends AbstractTestIterator {
033:
034:            protected int[] testArray = { 2, 4, 6, 8 };
035:
036:            public static Test suite() {
037:                return new TestSuite(TestArrayIterator2.class);
038:            }
039:
040:            public TestArrayIterator2(String testName) {
041:                super (testName);
042:            }
043:
044:            public Iterator makeEmptyIterator() {
045:                return new ArrayIterator(new int[0]);
046:            }
047:
048:            public Iterator makeFullIterator() {
049:                return new ArrayIterator(testArray);
050:            }
051:
052:            /*
053:             * We use these <code>makeArrayIterator</code> factory methods instead of
054:             * directly calling the constructor so as to allow subclasses
055:             * (e.g. TestArrayListIterator2) to use the existing test code.
056:             * 
057:             * @return ArrayIterator
058:             */
059:            public ArrayIterator makeArrayIterator() {
060:                return (ArrayIterator) makeEmptyIterator();
061:            }
062:
063:            public ArrayIterator makeArrayIterator(Object array) {
064:                return new ArrayIterator(array);
065:            }
066:
067:            public ArrayIterator makeArrayIterator(Object array, int index) {
068:                return new ArrayIterator(array, index);
069:            }
070:
071:            public ArrayIterator makeArrayIterator(Object array, int start,
072:                    int end) {
073:                return new ArrayIterator(array, start, end);
074:            }
075:
076:            public boolean supportsRemove() {
077:                return false;
078:            }
079:
080:            public void testIterator() {
081:                Iterator iter = (Iterator) makeFullIterator();
082:                for (int i = 0; i < testArray.length; i++) {
083:                    Integer testValue = new Integer(testArray[i]);
084:                    Number iterValue = (Number) iter.next();
085:
086:                    assertEquals("Iteration value is correct", testValue,
087:                            iterValue);
088:                }
089:
090:                assertTrue("Iterator should now be empty", !iter.hasNext());
091:
092:                try {
093:                    Object testValue = iter.next();
094:                } catch (Exception e) {
095:                    assertTrue("NoSuchElementException must be thrown", e
096:                            .getClass().equals(
097:                                    (new NoSuchElementException()).getClass()));
098:                }
099:            }
100:
101:            // proves that an ArrayIterator set with the constructor has the same number of elements
102:            // as an ArrayIterator set with setArray(Object) 
103:            public void testSetArray() {
104:                Iterator iter1 = makeArrayIterator(testArray);
105:                int count1 = 0;
106:                while (iter1.hasNext()) {
107:                    ++count1;
108:                    iter1.next();
109:                }
110:
111:                assertEquals("the count should be right using the constructor",
112:                        count1, testArray.length);
113:
114:                ArrayIterator iter2 = makeArrayIterator();
115:                iter2.setArray(testArray);
116:                int count2 = 0;
117:                while (iter2.hasNext()) {
118:                    ++count2;
119:                    iter2.next();
120:                }
121:
122:                assertEquals(
123:                        "the count should be right using setArray(Object)",
124:                        count2, testArray.length);
125:            }
126:
127:            public void testIndexedArray() {
128:                Iterator iter = makeArrayIterator(testArray, 2);
129:                int count = 0;
130:                while (iter.hasNext()) {
131:                    ++count;
132:                    iter.next();
133:                }
134:
135:                assertEquals(
136:                        "the count should be right using ArrayIterator(Object,2) ",
137:                        count, testArray.length - 2);
138:
139:                iter = makeArrayIterator(testArray, 1, testArray.length - 1);
140:                count = 0;
141:                while (iter.hasNext()) {
142:                    ++count;
143:                    iter.next();
144:                }
145:
146:                assertEquals(
147:                        "the count should be right using ArrayIterator(Object,1,"
148:                                + (testArray.length - 1) + ") ", count,
149:                        testArray.length - 2);
150:
151:                try {
152:                    iter = makeArrayIterator(testArray, -1);
153:                    fail("new ArrayIterator(Object,-1) should throw an ArrayIndexOutOfBoundsException");
154:                } catch (ArrayIndexOutOfBoundsException aioobe) {
155:                    // expected
156:                }
157:
158:                try {
159:                    iter = makeArrayIterator(testArray, testArray.length + 1);
160:                    fail("new ArrayIterator(Object,length+1) should throw an ArrayIndexOutOfBoundsException");
161:                } catch (ArrayIndexOutOfBoundsException aioobe) {
162:                    // expected
163:                }
164:
165:                try {
166:                    iter = makeArrayIterator(testArray, 0, -1);
167:                    fail("new ArrayIterator(Object,0,-1) should throw an ArrayIndexOutOfBoundsException");
168:                } catch (ArrayIndexOutOfBoundsException aioobe) {
169:                    // expected
170:                }
171:
172:                try {
173:                    iter = makeArrayIterator(testArray, 0, testArray.length + 1);
174:                    fail("new ArrayIterator(Object,0,length+1) should throw an ArrayIndexOutOfBoundsException");
175:                } catch (ArrayIndexOutOfBoundsException aioobe) {
176:                    // expected
177:                }
178:
179:                try {
180:                    iter = makeArrayIterator(testArray, 1, 1);
181:                    // expected not to fail
182:                } catch (IllegalArgumentException iae) {
183:                    // MODIFIED: an iterator over a zero-length section of array
184:                    //  should be perfectly legal behavior
185:                    fail("new ArrayIterator(Object,1,1) should NOT throw an IllegalArgumentException");
186:                }
187:
188:                try {
189:                    iter = makeArrayIterator(testArray, testArray.length - 1,
190:                            testArray.length - 2);
191:                    fail("new ArrayIterator(Object,length-2,length-1) should throw an IllegalArgumentException");
192:                } catch (IllegalArgumentException iae) {
193:                    // expected
194:                }
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.