Source Code Cross Referenced for TestLoopingIterator.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.Arrays;
020:        import java.util.List;
021:        import java.util.NoSuchElementException;
022:
023:        import junit.framework.Test;
024:        import junit.framework.TestCase;
025:        import junit.framework.TestSuite;
026:
027:        /**
028:         * Tests the LoopingIterator class.
029:         * 
030:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
031:         * 
032:         * @author Jonathan Carlson
033:         * @author Stephen Colebourne
034:         */
035:        public class TestLoopingIterator extends TestCase {
036:
037:            public TestLoopingIterator(String testName) {
038:                super (testName);
039:            }
040:
041:            public static Test suite() {
042:                return new TestSuite(TestLoopingIterator.class);
043:            }
044:
045:            /**
046:             * Tests constructor exception.
047:             */
048:            public void testConstructorEx() throws Exception {
049:                try {
050:                    new LoopingIterator(null);
051:                    fail();
052:                } catch (NullPointerException ex) {
053:                }
054:            }
055:
056:            /**
057:             * Tests whether an empty looping iterator works as designed.
058:             * @throws Exception  If something unexpected occurs.
059:             */
060:            public void testLooping0() throws Exception {
061:                List list = new ArrayList();
062:                LoopingIterator loop = new LoopingIterator(list);
063:                assertTrue("hasNext should return false",
064:                        loop.hasNext() == false);
065:
066:                try {
067:                    loop.next();
068:                    fail("NoSuchElementException was not thrown during next() call.");
069:                } catch (NoSuchElementException ex) {
070:                }
071:            }
072:
073:            /**
074:             * Tests whether a populated looping iterator works as designed.
075:             * @throws Exception  If something unexpected occurs.
076:             */
077:            public void testLooping1() throws Exception {
078:                List list = new ArrayList(Arrays.asList(new String[] { "a" }));
079:                LoopingIterator loop = new LoopingIterator(list);
080:
081:                assertTrue("1st hasNext should return true", loop.hasNext());
082:                assertEquals("a", loop.next());
083:
084:                assertTrue("2nd hasNext should return true", loop.hasNext());
085:                assertEquals("a", loop.next());
086:
087:                assertTrue("3rd hasNext should return true", loop.hasNext());
088:                assertEquals("a", loop.next());
089:
090:            }
091:
092:            /**
093:             * Tests whether a populated looping iterator works as designed.
094:             * @throws Exception  If something unexpected occurs.
095:             */
096:            public void testLooping2() throws Exception {
097:                List list = new ArrayList(Arrays
098:                        .asList(new String[] { "a", "b" }));
099:                LoopingIterator loop = new LoopingIterator(list);
100:
101:                assertTrue("1st hasNext should return true", loop.hasNext());
102:                assertEquals("a", loop.next());
103:
104:                assertTrue("2nd hasNext should return true", loop.hasNext());
105:                assertEquals("b", loop.next());
106:
107:                assertTrue("3rd hasNext should return true", loop.hasNext());
108:                assertEquals("a", loop.next());
109:
110:            }
111:
112:            /**
113:             * Tests whether a populated looping iterator works as designed.
114:             * @throws Exception  If something unexpected occurs.
115:             */
116:            public void testLooping3() throws Exception {
117:                List list = new ArrayList(Arrays.asList(new String[] { "a",
118:                        "b", "c" }));
119:                LoopingIterator loop = new LoopingIterator(list);
120:
121:                assertTrue("1st hasNext should return true", loop.hasNext());
122:                assertEquals("a", loop.next());
123:
124:                assertTrue("2nd hasNext should return true", loop.hasNext());
125:                assertEquals("b", loop.next());
126:
127:                assertTrue("3rd hasNext should return true", loop.hasNext());
128:                assertEquals("c", loop.next());
129:
130:                assertTrue("4th hasNext should return true", loop.hasNext());
131:                assertEquals("a", loop.next());
132:
133:            }
134:
135:            /**
136:             * Tests the remove() method on a LoopingIterator wrapped ArrayList.
137:             * @throws Exception  If something unexpected occurs.
138:             */
139:            public void testRemoving1() throws Exception {
140:                List list = new ArrayList(Arrays.asList(new String[] { "a",
141:                        "b", "c" }));
142:                LoopingIterator loop = new LoopingIterator(list);
143:                assertEquals("list should have 3 elements.", 3, list.size());
144:
145:                assertTrue("1st hasNext should return true", loop.hasNext());
146:                assertEquals("a", loop.next());
147:                loop.remove(); // removes a
148:                assertEquals("list should have 2 elements.", 2, list.size());
149:
150:                assertTrue("2nd hasNext should return true", loop.hasNext());
151:                assertEquals("b", loop.next());
152:                loop.remove(); // removes b
153:                assertEquals("list should have 1 elements.", 1, list.size());
154:
155:                assertTrue("3rd hasNext should return true", loop.hasNext());
156:                assertEquals("c", loop.next());
157:                loop.remove(); // removes c
158:                assertEquals("list should have 0 elements.", 0, list.size());
159:
160:                assertTrue("4th hasNext should return false",
161:                        loop.hasNext() == false);
162:                try {
163:                    loop.next();
164:                    fail("Expected NoSuchElementException to be thrown.");
165:                } catch (NoSuchElementException ex) {
166:                }
167:            }
168:
169:            /**
170:             * Tests the reset() method on a LoopingIterator wrapped ArrayList.
171:             * @throws Exception  If something unexpected occurs.
172:             */
173:            public void testReset() throws Exception {
174:                List list = new ArrayList(Arrays.asList(new String[] { "a",
175:                        "b", "c" }));
176:                LoopingIterator loop = new LoopingIterator(list);
177:
178:                assertEquals("a", loop.next());
179:                assertEquals("b", loop.next());
180:                loop.reset();
181:                assertEquals("a", loop.next());
182:                loop.reset();
183:                assertEquals("a", loop.next());
184:                assertEquals("b", loop.next());
185:                assertEquals("c", loop.next());
186:                loop.reset();
187:                assertEquals("a", loop.next());
188:                assertEquals("b", loop.next());
189:                assertEquals("c", loop.next());
190:            }
191:
192:            /**
193:             * Tests the size() method on a LoopingIterator wrapped ArrayList.
194:             * @throws Exception  If something unexpected occurs.
195:             */
196:            public void testSize() throws Exception {
197:                List list = new ArrayList(Arrays.asList(new String[] { "a",
198:                        "b", "c" }));
199:                LoopingIterator loop = new LoopingIterator(list);
200:
201:                assertEquals(3, loop.size());
202:                loop.next();
203:                loop.next();
204:                assertEquals(3, loop.size());
205:                loop.reset();
206:                assertEquals(3, loop.size());
207:                loop.next();
208:                loop.remove();
209:                assertEquals(2, loop.size());
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.