Source Code Cross Referenced for TestSet.java in  » Ajax » GWT » org » apache » commons » collections » 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 » Ajax » GWT » org.apache.commons.collections 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-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;
017:
018:        import java.util.Arrays;
019:        import java.util.Collection;
020:        import java.util.HashSet;
021:        import java.util.Iterator;
022:        import java.util.Set;
023:
024:        /**
025:         *  Tests base {@link Set} methods and contracts.<P>
026:         *
027:         *  Since {@link Set} doesn't stipulate much new behavior that isn't already
028:         *  found in {@link Collection}, this class basically just adds tests for
029:         *  {@link Set#equals()} and {@link Set#hashCode()} along with an updated
030:         *  {@link #verify()} that ensures elements do not appear more than once in the
031:         *  set.<P>
032:         *
033:         *  To use, subclass and override the {@link #makeEmptySet()}
034:         *  method.  You may have to override other protected methods if your
035:         *  set is not modifiable, or if your set restricts what kinds of
036:         *  elements may be added; see {@link TestCollection} for more details.<P>
037:         *
038:         *  @author Paul Jack
039:         *  @version $Id: TestSet.java,v 1.2.2.1 2004/05/22 12:14:05 scolebourne Exp $
040:         */
041:        public abstract class TestSet extends TestCollection {
042:
043:            /**
044:             *  Constructor.
045:             *
046:             *  @param name  name for test
047:             */
048:            public TestSet(String name) {
049:
050:            }
051:
052:            /**
053:             *  Makes an empty collection by invoking {@link #makeEmptySet()}.  
054:             *
055:             *  @return an empty collection
056:             */
057:            protected final Collection makeCollection() {
058:                return makeEmptySet();
059:            }
060:
061:            /**
062:             *  Makes a full collection by invoking {@link #makeFullSet()}.
063:             *
064:             *  @return a full collection
065:             */
066:            protected final Collection makeFullCollection() {
067:                return makeFullSet();
068:            }
069:
070:            /**
071:             *  Return the {@link TestCollection#collection} fixture, but cast as a
072:             *  Set.  
073:             */
074:            protected Set getSet() {
075:                return (Set) collection;
076:            }
077:
078:            /**
079:             *  Returns an empty {@link HashSet} for use in modification testing.
080:             *
081:             *  @return a confirmed empty collection
082:             */
083:            protected Collection makeConfirmedCollection() {
084:                return new HashSet();
085:            }
086:
087:            /**
088:             *  Returns a full {@link HashSet} for use in modification testing.
089:             *
090:             *  @return a confirmed full collection
091:             */
092:            protected Collection makeConfirmedFullCollection() {
093:                HashSet set = new HashSet();
094:                set.addAll(Arrays.asList(getFullElements()));
095:                return set;
096:            }
097:
098:            /**
099:             *  Return the {@link TestCollection#confirmed} fixture, but cast as a 
100:             *  Set.
101:             **/
102:            protected Set getConfirmedSet() {
103:                return (Set) confirmed;
104:            }
105:
106:            /**
107:             *  Makes an empty set.  The returned set should have no elements.
108:             *
109:             *  @return an empty set
110:             */
111:            protected abstract Set makeEmptySet();
112:
113:            /**
114:             *  Makes a full set by first creating an empty set and then adding
115:             *  all the elements returned by {@link #getFullElements()}.
116:             *
117:             *  Override if your set does not support the add operation.
118:             *
119:             *  @return a full set
120:             */
121:            protected Set makeFullSet() {
122:                Set set = makeEmptySet();
123:                set.addAll(Arrays.asList(getFullElements()));
124:                return set;
125:            }
126:
127:            /**
128:             *  Tests {@link Set#equals(Object)}.
129:             */
130:            public void testSetEquals() {
131:                resetEmpty();
132:                assertEquals("Empty sets should be equal", getSet(),
133:                        getConfirmedSet());
134:                verify();
135:
136:                HashSet set2 = new HashSet();
137:                set2.add("foo");
138:                assertTrue("Empty set shouldn't equal nonempty set", !getSet()
139:                        .equals(set2));
140:
141:                resetFull();
142:                assertEquals("Full sets should be equal", getSet(),
143:                        getConfirmedSet());
144:                verify();
145:
146:                set2.clear();
147:                set2.addAll(Arrays.asList(getOtherElements()));
148:                assertTrue("Sets with different contents shouldn't be equal",
149:                        !getSet().equals(set2));
150:            }
151:
152:            /**
153:             *  Tests {@link Set#hashCode()}.
154:             */
155:            public void testSetHashCode() {
156:                resetEmpty();
157:                assertEquals("Empty sets have equal hashCodes", getSet()
158:                        .hashCode(), getConfirmedSet().hashCode());
159:
160:                resetFull();
161:                assertEquals("Equal sets have equal hashCodes", getSet()
162:                        .hashCode(), getConfirmedSet().hashCode());
163:            }
164:
165:            /**
166:             *  Provides additional verifications for sets.
167:             */
168:            protected void verify() {
169:                super .verify();
170:                assertEquals("Sets should be equal", confirmed, collection);
171:                assertEquals("Sets should have equal hashCodes", confirmed
172:                        .hashCode(), collection.hashCode());
173:                HashSet set = new HashSet();
174:                Iterator iterator = collection.iterator();
175:                while (iterator.hasNext()) {
176:                    assertTrue(
177:                            "Set.iterator should only return unique elements",
178:                            set.add(iterator.next()));
179:                }
180:            }
181:
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.