Source Code Cross Referenced for LinkedHashSetTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » util » 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 » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  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:
017:        package org.apache.harmony.luni.tests.java.util;
018:
019:        import java.util.Arrays;
020:        import java.util.Iterator;
021:        import java.util.LinkedHashSet;
022:        import java.util.Set;
023:
024:        /**
025:         * @tests java.util.LinkedHashSet
026:         */
027:        public class LinkedHashSetTest extends junit.framework.TestCase {
028:
029:            LinkedHashSet hs;
030:
031:            static Object[] objArray;
032:            {
033:                objArray = new Object[1000];
034:                for (int i = 0; i < objArray.length; i++)
035:                    objArray[i] = new Integer(i);
036:            }
037:
038:            /**
039:             * @tests java.util.LinkedHashSet#LinkedHashSet()
040:             */
041:            public void test_Constructor() {
042:                // Test for method java.util.LinkedHashSet()
043:                LinkedHashSet hs2 = new LinkedHashSet();
044:                assertEquals("Created incorrect LinkedHashSet", 0, hs2.size());
045:            }
046:
047:            /**
048:             * @tests java.util.LinkedHashSet#LinkedHashSet(int)
049:             */
050:            public void test_ConstructorI() {
051:                // Test for method java.util.LinkedHashSet(int)
052:                LinkedHashSet hs2 = new LinkedHashSet(5);
053:                assertEquals("Created incorrect LinkedHashSet", 0, hs2.size());
054:                try {
055:                    new LinkedHashSet(-1);
056:                } catch (IllegalArgumentException e) {
057:                    return;
058:                }
059:                fail("Failed to throw IllegalArgumentException for capacity < 0");
060:            }
061:
062:            /**
063:             * @tests java.util.LinkedHashSet#LinkedHashSet(int, float)
064:             */
065:            public void test_ConstructorIF() {
066:                // Test for method java.util.LinkedHashSet(int, float)
067:                LinkedHashSet hs2 = new LinkedHashSet(5, (float) 0.5);
068:                assertEquals("Created incorrect LinkedHashSet", 0, hs2.size());
069:                try {
070:                    new LinkedHashSet(0, 0);
071:                } catch (IllegalArgumentException e) {
072:                    return;
073:                }
074:                fail("Failed to throw IllegalArgumentException for initial load factor <= 0");
075:            }
076:
077:            /**
078:             * @tests java.util.LinkedHashSet#LinkedHashSet(java.util.Collection)
079:             */
080:            public void test_ConstructorLjava_util_Collection() {
081:                // Test for method java.util.LinkedHashSet(java.util.Collection)
082:                LinkedHashSet hs2 = new LinkedHashSet(Arrays.asList(objArray));
083:                for (int counter = 0; counter < objArray.length; counter++)
084:                    assertTrue(
085:                            "LinkedHashSet does not contain correct elements",
086:                            hs.contains(objArray[counter]));
087:                assertTrue(
088:                        "LinkedHashSet created from collection incorrect size",
089:                        hs2.size() == objArray.length);
090:            }
091:
092:            /**
093:             * @tests java.util.LinkedHashSet#add(java.lang.Object)
094:             */
095:            public void test_addLjava_lang_Object() {
096:                // Test for method boolean java.util.LinkedHashSet.add(java.lang.Object)
097:                int size = hs.size();
098:                hs.add(new Integer(8));
099:                assertTrue("Added element already contained by set",
100:                        hs.size() == size);
101:                hs.add(new Integer(-9));
102:                assertTrue("Failed to increment set size after add",
103:                        hs.size() == size + 1);
104:                assertTrue("Failed to add element to set", hs
105:                        .contains(new Integer(-9)));
106:            }
107:
108:            /**
109:             * @tests java.util.LinkedHashSet#clear()
110:             */
111:            public void test_clear() {
112:                // Test for method void java.util.LinkedHashSet.clear()
113:                Set orgSet = (Set) hs.clone();
114:                hs.clear();
115:                Iterator i = orgSet.iterator();
116:                assertEquals("Returned non-zero size after clear", 0, hs.size());
117:                while (i.hasNext())
118:                    assertTrue("Failed to clear set", !hs.contains(i.next()));
119:            }
120:
121:            /**
122:             * @tests java.util.LinkedHashSet#clone()
123:             */
124:            public void test_clone() {
125:                // Test for method java.lang.Object java.util.LinkedHashSet.clone()
126:                LinkedHashSet hs2 = (LinkedHashSet) hs.clone();
127:                assertTrue("clone returned an equivalent LinkedHashSet",
128:                        hs != hs2);
129:                assertTrue("clone did not return an equal LinkedHashSet", hs
130:                        .equals(hs2));
131:            }
132:
133:            /**
134:             * @tests java.util.LinkedHashSet#contains(java.lang.Object)
135:             */
136:            public void test_containsLjava_lang_Object() {
137:                // Test for method boolean
138:                // java.util.LinkedHashSet.contains(java.lang.Object)
139:                assertTrue("Returned false for valid object", hs
140:                        .contains(objArray[90]));
141:                assertTrue("Returned true for invalid Object", !hs
142:                        .contains(new Object()));
143:
144:                LinkedHashSet s = new LinkedHashSet();
145:                s.add(null);
146:                assertTrue("Cannot handle null", s.contains(null));
147:            }
148:
149:            /**
150:             * @tests java.util.LinkedHashSet#isEmpty()
151:             */
152:            public void test_isEmpty() {
153:                // Test for method boolean java.util.LinkedHashSet.isEmpty()
154:                assertTrue("Empty set returned false", new LinkedHashSet()
155:                        .isEmpty());
156:                assertTrue("Non-empty set returned true", !hs.isEmpty());
157:            }
158:
159:            /**
160:             * @tests java.util.LinkedHashSet#iterator()
161:             */
162:            public void test_iterator() {
163:                // Test for method java.util.Iterator java.util.LinkedHashSet.iterator()
164:                Iterator i = hs.iterator();
165:                int x = 0;
166:                int j;
167:                for (j = 0; i.hasNext(); j++) {
168:                    Object oo = i.next();
169:                    if (oo != null) {
170:                        Integer ii = (Integer) oo;
171:                        assertTrue("Incorrect element found",
172:                                ii.intValue() == j);
173:                    } else {
174:                        assertTrue("Cannot find null", hs.contains(oo));
175:                    }
176:                    ++x;
177:                }
178:                assertTrue("Returned iteration of incorrect size",
179:                        hs.size() == x);
180:
181:                LinkedHashSet s = new LinkedHashSet();
182:                s.add(null);
183:                assertNull("Cannot handle null", s.iterator().next());
184:            }
185:
186:            /**
187:             * @tests java.util.LinkedHashSet#remove(java.lang.Object)
188:             */
189:            public void test_removeLjava_lang_Object() {
190:                // Test for method boolean
191:                // java.util.LinkedHashSet.remove(java.lang.Object)
192:                int size = hs.size();
193:                hs.remove(new Integer(98));
194:                assertTrue("Failed to remove element", !hs
195:                        .contains(new Integer(98)));
196:                assertTrue("Failed to decrement set size",
197:                        hs.size() == size - 1);
198:
199:                LinkedHashSet s = new LinkedHashSet();
200:                s.add(null);
201:                assertTrue("Cannot handle null", s.remove(null));
202:            }
203:
204:            /**
205:             * @tests java.util.LinkedHashSet#size()
206:             */
207:            public void test_size() {
208:                // Test for method int java.util.LinkedHashSet.size()
209:                assertTrue("Returned incorrect size",
210:                        hs.size() == (objArray.length + 1));
211:                hs.clear();
212:                assertEquals("Cleared set returned non-zero size", 0, hs.size());
213:            }
214:
215:            /**
216:             * Sets up the fixture, for example, open a network connection. This method
217:             * is called before a test is executed.
218:             */
219:            protected void setUp() {
220:                hs = new LinkedHashSet();
221:                for (int i = 0; i < objArray.length; i++)
222:                    hs.add(objArray[i]);
223:                hs.add(null);
224:            }
225:
226:            /**
227:             * Tears down the fixture, for example, close a network connection. This
228:             * method is called after a test is executed.
229:             */
230:            protected void tearDown() {
231:            }
232:        }
ww___w___._j___a__v__a2___s.co_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.