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


org.apache.commons.collections.AbstractTestObject
   org.apache.commons.collections.collection.AbstractTestCollection

All known Subclasses:   org.apache.commons.collections.buffer.TestSynchronizedBuffer,  org.apache.commons.collections.buffer.TestUnboundedFifoBuffer,  org.apache.commons.collections.collection.TestTransformedCollection,  org.apache.commons.collections.TestBoundedFifoBuffer,  org.apache.commons.collections.collection.TestPredicatedCollection,  org.apache.commons.collections.collection.TestUnmodifiableCollection,  org.apache.commons.collections.buffer.TestPriorityBuffer,  org.apache.commons.collections.TestBinaryHeap,  org.apache.commons.collections.TestUnboundedFifoBuffer,  org.apache.commons.collections.set.AbstractTestSet,  org.apache.commons.collections.list.AbstractTestList,  org.apache.commons.collections.collection.TestSynchronizedCollection,  org.apache.commons.collections.buffer.TestBoundedFifoBuffer,  org.apache.commons.collections.buffer.TestCircularFifoBuffer,  org.apache.commons.collections.buffer.TestUnmodifiableBuffer,  org.apache.commons.collections.collection.TestCompositeCollection,
AbstractTestCollection
abstract public class AbstractTestCollection extends AbstractTestObject (Code)
Abstract test class for 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 AbstractTestCollection.makeCollection() method. You might want to override some of the additional public 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 AbstractTestCollection.collection field holds an instance of your collection implementation; the AbstractTestCollection.confirmed field holds an instance of the confirmed collection implementation. The AbstractTestCollection.resetEmpty() and AbstractTestCollection.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 AbstractTestCollection.collection and AbstractTestCollection.confirmed , the AbstractTestCollection.verify() method is invoked to compare the results. You may want to override AbstractTestCollection.verify() to perform additional verifications. For instance, when testing the collection views of a map, AbstractTestMap would override AbstractTestCollection.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 AbstractTestList , AbstractTestSet , or AbstractTestBag , 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.
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   Rodney Waldhoff
author:
   Paul Jack
author:
   Michael A. Smith
author:
   Neil O'Toole
author:
   Stephen Colebourne



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

Constructor Summary
public  AbstractTestCollection(String testName)
     JUnit constructor.

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

Default implementation returns true.

public  booleanisEqualsCheckable()
     Returns true to indicate that the collection supports equals() comparisons.
public  booleanisFailFastSupported()
     Returns true to indicate that the collection supports fail fast iterators.
public  booleanisNullSupported()
     Returns true to indicate that the collection supports holding null.
public  booleanisRemoveSupported()
     Returns true if the collections produced by AbstractTestCollection.makeCollection() and AbstractTestCollection.makeFullCollection() support the remove, removeAll, retainAll, clear and iterator().remove() methods. Default implementation returns true.
abstract public  CollectionmakeCollection()
     Return a new, empty Collection to be used for testing.
abstract public  CollectionmakeConfirmedCollection()
     Returns a confirmed empty collection.
abstract public  CollectionmakeConfirmedFullCollection()
     Returns a confirmed full collection. For instance, an java.util.ArrayList for lists or a java.util.HashSet for sets.
public  CollectionmakeFullCollection()
     Returns a full collection to be used for testing.
public  ObjectmakeObject()
     Returns an empty collection for Object tests.
public  voidresetEmpty()
     Resets the AbstractTestCollection.collection and AbstractTestCollection.confirmed fields to empty collections.
public  voidresetFull()
     Resets the AbstractTestCollection.collection and AbstractTestCollection.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  voidtestCollectionIteratorFailFast()
     Tests that the collection's iterator is fail-fast.
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  voidtestCollectionToArray()
     Tests Collection.toArray .
public  voidtestCollectionToArray2()
     Tests Collection.toArray(Object[]) .
public  voidtestCollectionToString()
     Tests toString on a collection.
public  voidtestSerializeDeserializeThenCompare()
    
public  voidtestUnsupportedAdd()
     If AbstractTestCollection.isAddSupported() returns false, tests that add operations raise UnsupportedOperationException.
public  voidtestUnsupportedRemove()
     If isRemoveSupported() returns false, tests to see that remove operations raise an UnsupportedOperationException.
public  voidverify()
     Verifies that AbstractTestCollection.collection and AbstractTestCollection.confirmed have identical state.

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



confirmed
public 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.




Constructor Detail
AbstractTestCollection
public AbstractTestCollection(String testName)(Code)
JUnit constructor.
Parameters:
  testName - the test class name




Method Detail
areEqualElementsDistinguishable
public 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.




cloneMapEntry
public Map.Entry cloneMapEntry(Map.Entry entry)(Code)
Creates a new Map Entry that is independent of the first and the map.



getFullElements
public Object[] getFullElements()(Code)
Returns an array of objects that are contained in a collection produced by AbstractTestCollection.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. null is added if allowed. Override if you require specific testing elements. Note that if you override AbstractTestCollection.makeFullCollection() , you must override this method to reflect the contents of a full collection.




getFullNonNullElements
public Object[] getFullNonNullElements()(Code)
Returns a list of elements suitable for return by AbstractTestCollection.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 Object[] getFullNonNullStringElements()(Code)
Returns a list of string elements suitable for return by AbstractTestCollection.getFullElements() . Override getFullElements to return the results of this method if your collection does not support heterogenous elements or the null element.



getOtherElements
public 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 AbstractTestCollection.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 Object[] getOtherNonNullElements()(Code)
Returns the default list of objects returned by AbstractTestCollection.getOtherElements() . Includes many objects of different types.



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



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

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




isEqualsCheckable
public boolean isEqualsCheckable()(Code)
Returns true to indicate that the collection supports equals() comparisons. This implementation returns false;



isFailFastSupported
public boolean isFailFastSupported()(Code)
Returns true to indicate that the collection supports fail fast iterators. The default implementation returns true;



isNullSupported
public boolean isNullSupported()(Code)
Returns true to indicate that the collection supports holding null. The default implementation returns true;



isRemoveSupported
public boolean isRemoveSupported()(Code)
Returns true if the collections produced by AbstractTestCollection.makeCollection() and AbstractTestCollection.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 public Collection makeCollection()(Code)
Return a new, empty Collection to be used for testing.



makeConfirmedCollection
abstract public 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 public 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 AbstractTestCollection.getFullElements() . a confirmed full collection



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



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



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



resetFull
public void resetFull()(Code)
Resets the AbstractTestCollection.collection and AbstractTestCollection.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 .



testCollectionIteratorFailFast
public void testCollectionIteratorFailFast()(Code)
Tests that the collection's iterator is fail-fast.



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 .



testCollectionToArray
public void testCollectionToArray()(Code)
Tests Collection.toArray .



testCollectionToArray2
public void testCollectionToArray2()(Code)
Tests Collection.toArray(Object[]) .



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



testSerializeDeserializeThenCompare
public void testSerializeDeserializeThenCompare() throws Exception(Code)



testUnsupportedAdd
public void testUnsupportedAdd()(Code)
If AbstractTestCollection.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
public void verify()(Code)
Verifies that AbstractTestCollection.collection and AbstractTestCollection.confirmed have identical state.



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

Methods inherited from org.apache.commons.collections.AbstractTestObject
protected String getCanonicalEmptyCollectionName(Object object)(Code)(Java Doc)
protected String getCanonicalFullCollectionName(Object object)(Code)(Java Doc)
public String getCompatibilityVersion()(Code)(Java Doc)
public boolean isEqualsCheckable()(Code)(Java Doc)
public boolean isTestSerialization()(Code)(Java Doc)
abstract public Object makeObject()(Code)(Java Doc)
protected Object readExternalFormFromBytes(byte[] b) throws IOException, ClassNotFoundException(Code)(Java Doc)
protected Object readExternalFormFromDisk(String path) throws IOException, ClassNotFoundException(Code)(Java Doc)
protected boolean skipSerializedCanonicalTests()(Code)(Java Doc)
public boolean supportsEmptyCollections()(Code)(Java Doc)
public boolean supportsFullCollections()(Code)(Java Doc)
public void testCanonicalEmptyCollectionExists()(Code)(Java Doc)
public void testCanonicalFullCollectionExists()(Code)(Java Doc)
public void testEqualsNull()(Code)(Java Doc)
public void testObjectEqualsSelf()(Code)(Java Doc)
public void testObjectHashCodeEqualsContract()(Code)(Java Doc)
public void testObjectHashCodeEqualsSelfHashCode()(Code)(Java Doc)
public void testSerializeDeserializeThenCompare() throws Exception(Code)(Java Doc)
public void testSimpleSerialization() throws Exception(Code)(Java Doc)
protected byte[] writeExternalFormToBytes(Serializable o) throws IOException(Code)(Java Doc)
protected void writeExternalFormToDisk(Serializable o, String path) throws IOException(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.