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


001:        /*
002:         *  Copyright 2003-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.set;
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.Set;
023:
024:        import junit.framework.Test;
025:        import junit.framework.TestSuite;
026:
027:        /**
028:         * Extension of {@link TestSet} for exercising the {@link ListOrderedSet}
029:         * implementation.
030:         *
031:         * @since Commons Collections 3.0
032:         * @version $Revision: 332769 $ $Date: 2005-11-12 12:40:01 +0000 (Sat, 12 Nov 2005) $
033:         * 
034:         * @author Henning P. Schmiedehausen
035:         * @author Stephen Colebourne
036:         */
037:        public class TestListOrderedSet extends AbstractTestSet {
038:
039:            public TestListOrderedSet(String testName) {
040:                super (testName);
041:            }
042:
043:            public static Test suite() {
044:                return new TestSuite(TestListOrderedSet.class);
045:            }
046:
047:            public static void main(String args[]) {
048:                String[] testCaseName = { TestListOrderedSet.class.getName() };
049:                junit.textui.TestRunner.main(testCaseName);
050:            }
051:
052:            public Set makeEmptySet() {
053:                return ListOrderedSet.decorate(new HashSet());
054:            }
055:
056:            protected Set setupSet() {
057:                Set set = makeEmptySet();
058:
059:                for (int i = 0; i < 10; i++) {
060:                    set.add(Integer.toString(i));
061:                }
062:                return set;
063:            }
064:
065:            public void testOrdering() {
066:                Set set = setupSet();
067:                Iterator it = set.iterator();
068:
069:                for (int i = 0; i < 10; i++) {
070:                    assertEquals("Sequence is wrong", Integer.toString(i), it
071:                            .next());
072:                }
073:
074:                for (int i = 0; i < 10; i += 2) {
075:                    assertTrue("Must be able to remove int", set.remove(Integer
076:                            .toString(i)));
077:                }
078:
079:                it = set.iterator();
080:                for (int i = 1; i < 10; i += 2) {
081:                    assertEquals("Sequence is wrong after remove ", Integer
082:                            .toString(i), it.next());
083:                }
084:
085:                for (int i = 0; i < 10; i++) {
086:                    set.add(Integer.toString(i));
087:                }
088:
089:                assertEquals("Size of set is wrong!", 10, set.size());
090:
091:                it = set.iterator();
092:                for (int i = 1; i < 10; i += 2) {
093:                    assertEquals("Sequence is wrong", Integer.toString(i), it
094:                            .next());
095:                }
096:                for (int i = 0; i < 10; i += 2) {
097:                    assertEquals("Sequence is wrong", Integer.toString(i), it
098:                            .next());
099:                }
100:            }
101:
102:            private static final Integer ZERO = new Integer(0);
103:            private static final Integer ONE = new Integer(1);
104:            private static final Integer TWO = new Integer(2);
105:            private static final Integer THREE = new Integer(3);
106:
107:            public void testListAddRemove() {
108:                ListOrderedSet set = (ListOrderedSet) makeEmptySet();
109:                List view = set.asList();
110:                set.add(ZERO);
111:                set.add(ONE);
112:                set.add(TWO);
113:
114:                assertEquals(3, set.size());
115:                assertSame(ZERO, set.get(0));
116:                assertSame(ONE, set.get(1));
117:                assertSame(TWO, set.get(2));
118:                assertEquals(3, view.size());
119:                assertSame(ZERO, view.get(0));
120:                assertSame(ONE, view.get(1));
121:                assertSame(TWO, view.get(2));
122:
123:                assertEquals(0, set.indexOf(ZERO));
124:                assertEquals(1, set.indexOf(ONE));
125:                assertEquals(2, set.indexOf(TWO));
126:
127:                set.remove(1);
128:                assertEquals(2, set.size());
129:                assertSame(ZERO, set.get(0));
130:                assertSame(TWO, set.get(1));
131:                assertEquals(2, view.size());
132:                assertSame(ZERO, view.get(0));
133:                assertSame(TWO, view.get(1));
134:            }
135:
136:            public void testListAddIndexed() {
137:                ListOrderedSet set = (ListOrderedSet) makeEmptySet();
138:                set.add(ZERO);
139:                set.add(TWO);
140:
141:                set.add(1, ONE);
142:                assertEquals(3, set.size());
143:                assertSame(ZERO, set.get(0));
144:                assertSame(ONE, set.get(1));
145:                assertSame(TWO, set.get(2));
146:
147:                set.add(0, ONE);
148:                assertEquals(3, set.size());
149:                assertSame(ZERO, set.get(0));
150:                assertSame(ONE, set.get(1));
151:                assertSame(TWO, set.get(2));
152:
153:                List list = new ArrayList();
154:                list.add(ZERO);
155:                list.add(TWO);
156:
157:                set.addAll(0, list);
158:                assertEquals(3, set.size());
159:                assertSame(ZERO, set.get(0));
160:                assertSame(ONE, set.get(1));
161:                assertSame(TWO, set.get(2));
162:
163:                list.add(0, THREE); // list = [3,0,2]
164:                set.remove(TWO); //  set = [0,1]
165:                set.addAll(1, list);
166:                assertEquals(4, set.size());
167:                assertSame(ZERO, set.get(0));
168:                assertSame(THREE, set.get(1));
169:                assertSame(TWO, set.get(2));
170:                assertSame(ONE, set.get(3));
171:            }
172:
173:            public void testListAddReplacing() {
174:                ListOrderedSet set = (ListOrderedSet) makeEmptySet();
175:                A a = new A();
176:                B b = new B();
177:                set.add(a);
178:                assertEquals(1, set.size());
179:                set.add(b); // will match but not replace A as equal
180:                assertEquals(1, set.size());
181:                assertSame(a, set.getSet().iterator().next());
182:                assertSame(a, set.iterator().next());
183:                assertSame(a, set.get(0));
184:                assertSame(a, set.asList().get(0));
185:            }
186:
187:            static class A {
188:                public boolean equals(Object obj) {
189:                    return (obj instanceof  A || obj instanceof  B);
190:                }
191:
192:                public int hashCode() {
193:                    return 1;
194:                }
195:            }
196:
197:            static class B {
198:                public boolean equals(Object obj) {
199:                    return (obj instanceof  A || obj instanceof  B);
200:                }
201:
202:                public int hashCode() {
203:                    return 1;
204:                }
205:            }
206:
207:            public void testDecorator() {
208:                try {
209:                    ListOrderedSet.decorate((List) null);
210:                    fail();
211:                } catch (IllegalArgumentException ex) {
212:                }
213:                try {
214:                    ListOrderedSet.decorate((Set) null);
215:                    fail();
216:                } catch (IllegalArgumentException ex) {
217:                }
218:                try {
219:                    ListOrderedSet.decorate(null, null);
220:                    fail();
221:                } catch (IllegalArgumentException ex) {
222:                }
223:                try {
224:                    ListOrderedSet.decorate(new HashSet(), null);
225:                    fail();
226:                } catch (IllegalArgumentException ex) {
227:                }
228:                try {
229:                    ListOrderedSet.decorate(null, new ArrayList());
230:                    fail();
231:                } catch (IllegalArgumentException ex) {
232:                }
233:            }
234:
235:            public String getCompatibilityVersion() {
236:                return "3.1";
237:            }
238:
239:            //    public void testCreate() throws Exception {
240:            //        resetEmpty();
241:            //        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/ListOrderedSet.emptyCollection.version3.1.obj");
242:            //        resetFull();
243:            //        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/ListOrderedSet.fullCollection.version3.1.obj");
244:            //    }
245:
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.