Source Code Cross Referenced for AbstractTestSet.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 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.set;
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:        import org.apache.commons.collections.collection.AbstractTestCollection;
025:
026:        /**
027:         * Abstract test class for {@link Set} methods and contracts.
028:         * <p>
029:         * Since {@link Set} doesn't stipulate much new behavior that isn't already
030:         * found in {@link Collection}, this class basically just adds tests for
031:         * {@link Set#equals} and {@link Set#hashCode()} along with an updated
032:         * {@link #verify()} that ensures elements do not appear more than once in the
033:         * set.
034:         * <p>
035:         * To use, subclass and override the {@link #makeEmptySet()}
036:         * method.  You may have to override other protected methods if your
037:         * set is not modifiable, or if your set restricts what kinds of
038:         * elements may be added; see {@link AbstractTestCollection} for more details.
039:         *
040:         * @since Commons Collections 3.0
041:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
042:         * 
043:         * @author Paul Jack
044:         */
045:        public abstract class AbstractTestSet extends AbstractTestCollection {
046:
047:            /**
048:             * JUnit constructor.
049:             *
050:             * @param name  name for test
051:             */
052:            public AbstractTestSet(String name) {
053:                super (name);
054:            }
055:
056:            //-----------------------------------------------------------------------
057:            /**
058:             * Provides additional verifications for sets.
059:             */
060:            public void verify() {
061:                super .verify();
062:
063:                assertEquals("Sets should be equal", confirmed, collection);
064:                assertEquals("Sets should have equal hashCodes", confirmed
065:                        .hashCode(), collection.hashCode());
066:                Collection set = makeConfirmedCollection();
067:                Iterator iterator = collection.iterator();
068:                while (iterator.hasNext()) {
069:                    assertTrue(
070:                            "Set.iterator should only return unique elements",
071:                            set.add(iterator.next()));
072:                }
073:            }
074:
075:            //-----------------------------------------------------------------------
076:            /**
077:             * Set equals method is defined.
078:             */
079:            public boolean isEqualsCheckable() {
080:                return true;
081:            }
082:
083:            /**
084:             * Returns an empty Set for use in modification testing.
085:             *
086:             * @return a confirmed empty collection
087:             */
088:            public Collection makeConfirmedCollection() {
089:                return new HashSet();
090:            }
091:
092:            /**
093:             * Returns a full Set for use in modification testing.
094:             *
095:             * @return a confirmed full collection
096:             */
097:            public Collection makeConfirmedFullCollection() {
098:                Collection set = makeConfirmedCollection();
099:                set.addAll(Arrays.asList(getFullElements()));
100:                return set;
101:            }
102:
103:            /**
104:             * Makes an empty set.  The returned set should have no elements.
105:             *
106:             * @return an empty set
107:             */
108:            public abstract Set makeEmptySet();
109:
110:            /**
111:             * Makes a full set by first creating an empty set and then adding
112:             * all the elements returned by {@link #getFullElements()}.
113:             *
114:             * Override if your set does not support the add operation.
115:             *
116:             * @return a full set
117:             */
118:            public Set makeFullSet() {
119:                Set set = makeEmptySet();
120:                set.addAll(Arrays.asList(getFullElements()));
121:                return set;
122:            }
123:
124:            /**
125:             * Makes an empty collection by invoking {@link #makeEmptySet()}.  
126:             *
127:             * @return an empty collection
128:             */
129:            public final Collection makeCollection() {
130:                return makeEmptySet();
131:            }
132:
133:            /**
134:             * Makes a full collection by invoking {@link #makeFullSet()}.
135:             *
136:             * @return a full collection
137:             */
138:            public final Collection makeFullCollection() {
139:                return makeFullSet();
140:            }
141:
142:            //-----------------------------------------------------------------------
143:            /**
144:             * Return the {@link AbstractTestCollection#collection} fixture, but cast as a Set.  
145:             */
146:            public Set getSet() {
147:                return (Set) collection;
148:            }
149:
150:            /**
151:             * Return the {@link AbstractTestCollection#confirmed} fixture, but cast as a Set.
152:             */
153:            public Set getConfirmedSet() {
154:                return (Set) confirmed;
155:            }
156:
157:            //-----------------------------------------------------------------------
158:            /**
159:             * Tests {@link Set#equals(Object)}.
160:             */
161:            public void testSetEquals() {
162:                resetEmpty();
163:                assertEquals("Empty sets should be equal", getSet(),
164:                        getConfirmedSet());
165:                verify();
166:
167:                Collection set2 = makeConfirmedCollection();
168:                set2.add("foo");
169:                assertTrue("Empty set shouldn't equal nonempty set", !getSet()
170:                        .equals(set2));
171:
172:                resetFull();
173:                assertEquals("Full sets should be equal", getSet(),
174:                        getConfirmedSet());
175:                verify();
176:
177:                set2.clear();
178:                set2.addAll(Arrays.asList(getOtherElements()));
179:                assertTrue("Sets with different contents shouldn't be equal",
180:                        !getSet().equals(set2));
181:            }
182:
183:            /**
184:             * Tests {@link Set#hashCode()}.
185:             */
186:            public void testSetHashCode() {
187:                resetEmpty();
188:                assertEquals("Empty sets have equal hashCodes", getSet()
189:                        .hashCode(), getConfirmedSet().hashCode());
190:
191:                resetFull();
192:                assertEquals("Equal sets have equal hashCodes", getSet()
193:                        .hashCode(), getConfirmedSet().hashCode());
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.