Java Doc for TestCollection.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 Reference  Class Diagram Java Document (Java Doc) 


org.apache.commons.collections.TestObject
   org.apache.commons.collections.TestCollection

All known Subclasses:   org.apache.commons.collections.TestList,  org.apache.commons.collections.TestSet,
TestCollection
abstract public class TestCollection extends TestObject (Code)
Tests base java.util.Collection methods and contracts.

You should create a concrete subclass of this class to test any custom Collection implementation. At minimum, you'll have to implement the TestCollection.makeCollection() method. You might want to override some of the additional protected methods as well:

Element Population Methods

Override these if your collection restricts what kind of elements are allowed (for instance, if null is not permitted):

Supported Operation Methods

Override these if your collection doesn't support certain operations:

Fixture Methods

Fixtures are used to verify that the the operation results in correct state for the collection. Basically, the operation is performed against your collection implementation, and an identical operation is performed against a confirmed collection implementation. A confirmed collection implementation is something like java.util.ArrayList, which is known to conform exactly to its collection interface's contract. After the operation takes place on both your collection implementation and the confirmed collection implementation, the two collections are compared to see if their state is identical. The comparison is usually much more involved than a simple equals test. This verification is used to ensure proper modifications are made along with ensuring that the collection does not change when read-only modifications are made.

The TestCollection.collection field holds an instance of your collection implementation; the TestCollection.confirmed field holds an instance of the confirmed collection implementation. The TestCollection.resetEmpty() and TestCollection.resetFull() methods set these fields to empty or full collections, so that tests can proceed from a known state.

After a modification operation to both TestCollection.collection and TestCollection.confirmed , the TestCollection.verify() method is invoked to compare the results. You may want to override TestCollection.verify() to perform additional verifications. For instance, when testing the collection views of a map, TestMap would override TestCollection.verify() to make sure the map is changed after the collection view is changed. If you're extending this class directly, you will have to provide implementations for the following:

Those methods should provide a confirmed collection implementation that's compatible with your collection implementation.

If you're extending TestList , TestSet , or TestBag , you probably don't have to worry about the above methods, because those three classes already override the methods to provide standard JDK confirmed collections.

Other notes

If your Collection fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your Collection fails. For instance, the TestCollection.testIteratorFailFast() method is provided since most collections have fail-fast iterators; however, that's not strictly required by the collection contract, so you may want to override that method to do nothing.


author:
   Rodney Waldhoff
author:
   Paul Jack
author:
   Michael A. Smith
version:
   $Id: TestCollection.java,v 1.9.2.1 2004/05/22 12:14:05 scolebourne Exp $



Field Summary
protected  Collectioncollection
     A collection instance that will be used for testing.
protected  Collectionconfirmed
     Confirmed collection.


Method Summary
protected  booleanareEqualElementsDistinguishable()
     Specifies whether equal elements in the collection are, in fact, distinguishable with information not readily available.
protected  Object[]getFullElements()
     Returns an array of objects that are contained in a collection produced by TestCollection.makeFullCollection() .
public static  Object[]getFullNonNullElements()
     Returns a list of elements suitable for return by TestCollection.getFullElements() .
public static  Object[]getFullNonNullStringElements()
     Returns a list of string elements suitable for return by TestCollection.getFullElements() .
protected  Object[]getOtherElements()
     Returns an array of elements that are not contained in a full collection.
public static  Object[]getOtherNonNullElements()
     Returns the default list of objects returned by TestCollection.getOtherElements() .
public static  Object[]getOtherNonNullStringElements()
     Returns a list of string elements suitable for return by TestCollection.getOtherElements() .
protected  booleanisAddSupported()
     Returns true if the collections produced by TestCollection.makeCollection() and TestCollection.makeFullCollection() support the add and addAll operations.

Default implementation returns true.

protected  booleanisRemoveSupported()
     Returns true if the collections produced by TestCollection.makeCollection() and TestCollection.makeFullCollection() support the remove, removeAll, retainAll, clear and iterator().remove() methods. Default implementation returns true.
abstract protected  CollectionmakeCollection()
     Return a new, empty Collection to be used for testing.
abstract protected  CollectionmakeConfirmedCollection()
     Returns a confirmed empty collection.
abstract protected  CollectionmakeConfirmedFullCollection()
     Returns a confirmed full collection. For instance, an java.util.ArrayList for lists or a java.util.HashSet for sets.
protected  CollectionmakeFullCollection()
     Returns a full collection to be used for testing.
public  ObjectmakeObject()
     Returns an empty collection for Object tests.
protected  voidresetEmpty()
     Resets the TestCollection.collection and TestCollection.confirmed fields to empty collections.
protected  voidresetFull()
     Resets the TestCollection.collection and TestCollection.confirmed fields to full collections.
public  voidtestCollectionAdd()
     Tests Collection.add(Object) .
public  voidtestCollectionAddAll()
     Tests Collection.addAll(Collection) .
public  voidtestCollectionClear()
     Test Collection.clear .
public  voidtestCollectionContains()
     Tests Collection.contains(Object) .
public  voidtestCollectionContainsAll()
     Tests Collection.containsAll(Collection) .
public  voidtestCollectionIsEmpty()
     Tests Collection.isEmpty .
public  voidtestCollectionIterator()
     Tests the read-only functionality of Collection.iterator .
public  voidtestCollectionIteratorRemove()
     Tests removals from Collection.iterator .
public  voidtestCollectionRemove()
     Tests Collection.remove(Object) .
public  voidtestCollectionRemoveAll()
     Tests Collection.removeAll(Collection) .
public  voidtestCollectionRetainAll()
     Tests Collection.retainAll(Collection) .
public  voidtestCollectionSize()
     Tests Collection.size .
public  voidtestCollectionToString()
     Tests toString on a collection.
public  voidtestUnsupportedAdd()
     If TestCollection.isAddSupported() returns false, tests that add operations raise UnsupportedOperationException.
public  voidtestUnsupportedRemove()
     If isRemoveSupported() returns false, tests to see that remove operations raise an UnsupportedOperationException.
protected  voidverify()
     Verifies that TestCollection.collection and TestCollection.confirmed have identical state.

Field Detail
collection
protected Collection collection(Code)
A collection instance that will be used for testing.



confirmed
protected Collection confirmed(Code)
Confirmed collection. This is an instance of a collection that is confirmed to conform exactly to the java.util.Collection contract. Modification operations are tested by performing a mod on your collection, performing the exact same mod on an equivalent confirmed collection, and then calling verify() to make sure your collection still matches the confirmed collection.





Method Detail
areEqualElementsDistinguishable
protected boolean areEqualElementsDistinguishable()(Code)
Specifies whether equal elements in the collection are, in fact, distinguishable with information not readily available. That is, if a particular value is to be removed from the collection, then there is one and only one value that can be removed, even if there are other elements which are equal to it.

In most collection cases, elements are not distinguishable (equal is equal), thus this method defaults to return false. In some cases, however, they are. For example, the collection returned from the map's values() collection view are backed by the map, so while there may be two values that are equal, their associated keys are not. Since the keys are distinguishable, the values are.

This flag is used to skip some verifications for iterator.remove() where it is impossible to perform an equivalent modification on the confirmed collection because it is not possible to determine which value in the confirmed collection to actually remove. Tests that override the default (i.e. where equal elements are distinguishable), should provide additional tests on iterator.remove() to make sure the proper elements are removed when remove() is called on the iterator.




getFullElements
protected Object[] getFullElements()(Code)
Returns an array of objects that are contained in a collection produced by TestCollection.makeFullCollection() . Every element in the returned array must be an element in a full collection.

The default implementation returns a heterogenous array of objects with some duplicates and with the null element. Override if you require specific testing elements. Note that if you override TestCollection.makeFullCollection() , you must override this method to reflect the contents of a full collection.




getFullNonNullElements
public static Object[] getFullNonNullElements()(Code)
Returns a list of elements suitable for return by TestCollection.getFullElements() . The array returned by this method does not include null, but does include a variety of objects of different types. Override getFullElements to return the results of this method if your collection does not support the null element.



getFullNonNullStringElements
public static Object[] getFullNonNullStringElements()(Code)
Returns a list of string elements suitable for return by TestCollection.getFullElements() . Override getFullElements to return the results of this method if your collection does not support heterogenous elements or the null element.



getOtherElements
protected Object[] getOtherElements()(Code)
Returns an array of elements that are not contained in a full collection. Every element in the returned array must not exist in a collection returned by TestCollection.makeFullCollection() . The default implementation returns a heterogenous array of elements without null. Note that some of the tests add these elements to an empty or full collection, so if your collection restricts certain kinds of elements, you should override this method.



getOtherNonNullElements
public static Object[] getOtherNonNullElements()(Code)
Returns the default list of objects returned by TestCollection.getOtherElements() . Includes many objects of different types.



getOtherNonNullStringElements
public static Object[] getOtherNonNullStringElements()(Code)
Returns a list of string elements suitable for return by TestCollection.getOtherElements() . Override getOtherElements to return the results of this method if your collection does not support heterogenous elements or the null element.



isAddSupported
protected boolean isAddSupported()(Code)
Returns true if the collections produced by TestCollection.makeCollection() and TestCollection.makeFullCollection() support the add and addAll operations.

Default implementation returns true. Override if your collection class does not support add or addAll.




isRemoveSupported
protected boolean isRemoveSupported()(Code)
Returns true if the collections produced by TestCollection.makeCollection() and TestCollection.makeFullCollection() support the remove, removeAll, retainAll, clear and iterator().remove() methods. Default implementation returns true. Override if your collection class does not support removal operations.



makeCollection
abstract protected Collection makeCollection()(Code)
Return a new, empty Collection to be used for testing.



makeConfirmedCollection
abstract protected Collection makeConfirmedCollection()(Code)
Returns a confirmed empty collection. For instance, an java.util.ArrayList for lists or a java.util.HashSet for sets. a confirmed empty collection



makeConfirmedFullCollection
abstract protected Collection makeConfirmedFullCollection()(Code)
Returns a confirmed full collection. For instance, an java.util.ArrayList for lists or a java.util.HashSet for sets. The returned collection should contain the elements returned by TestCollection.getFullElements() . a confirmed full collection



makeFullCollection
protected Collection makeFullCollection()(Code)
Returns a full collection to be used for testing. The collection returned by this method should contain every element returned by TestCollection.getFullElements() . The default implementation, in fact, simply invokes addAll on an empty collection with the results of TestCollection.getFullElements() . Override this default if your collection doesn't support addAll.



makeObject
public Object makeObject()(Code)
Returns an empty collection for Object tests.



resetEmpty
protected void resetEmpty()(Code)
Resets the TestCollection.collection and TestCollection.confirmed fields to empty collections. Invoke this method before performing a modification test.



resetFull
protected void resetFull()(Code)
Resets the TestCollection.collection and TestCollection.confirmed fields to full collections. Invoke this method before performing a modification test.



testCollectionAdd
public void testCollectionAdd()(Code)
Tests Collection.add(Object) .



testCollectionAddAll
public void testCollectionAddAll()(Code)
Tests Collection.addAll(Collection) .



testCollectionClear
public void testCollectionClear()(Code)
Test Collection.clear .



testCollectionContains
public void testCollectionContains()(Code)
Tests Collection.contains(Object) .



testCollectionContainsAll
public void testCollectionContainsAll()(Code)
Tests Collection.containsAll(Collection) .



testCollectionIsEmpty
public void testCollectionIsEmpty()(Code)
Tests Collection.isEmpty .



testCollectionIterator
public void testCollectionIterator()(Code)
Tests the read-only functionality of Collection.iterator .



testCollectionIteratorRemove
public void testCollectionIteratorRemove()(Code)
Tests removals from Collection.iterator .



testCollectionRemove
public void testCollectionRemove()(Code)
Tests Collection.remove(Object) .



testCollectionRemoveAll
public void testCollectionRemoveAll()(Code)
Tests Collection.removeAll(Collection) .



testCollectionRetainAll
public void testCollectionRetainAll()(Code)
Tests Collection.retainAll(Collection) .



testCollectionSize
public void testCollectionSize()(Code)
Tests Collection.size .



testCollectionToString
public void testCollectionToString()(Code)
Tests toString on a collection.



testUnsupportedAdd
public void testUnsupportedAdd()(Code)
If TestCollection.isAddSupported() returns false, tests that add operations raise UnsupportedOperationException.



testUnsupportedRemove
public void testUnsupportedRemove()(Code)
If isRemoveSupported() returns false, tests to see that remove operations raise an UnsupportedOperationException.



verify
protected void verify()(Code)
Verifies that TestCollection.collection and TestCollection.confirmed have identical state.



Fields inherited from org.apache.commons.collections.TestObject
final public static int COLLECTIONS_MAJOR_VERSION(Code)(Java Doc)

Methods inherited from org.apache.commons.collections.TestObject
public String getCanonicalEmptyCollectionName(Object object)(Code)(Java Doc)
public String getCanonicalFullCollectionName(Object object)(Code)(Java Doc)
public int getCompatibilityVersion()(Code)(Java Doc)
abstract public Object makeObject()(Code)(Java Doc)
public boolean supportsEmptyCollections()(Code)(Java Doc)
public boolean supportsFullCollections()(Code)(Java Doc)
public void testObjectEqualsSelf()(Code)(Java Doc)
public void testObjectHashCodeEqualsContract()(Code)(Java Doc)
public void testObjectHashCodeEqualsSelfHashCode()(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.