mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-13 05:26:34 +00:00
Generify
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_jdk5_branch@471578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8eab22e729
commit
52674fa23d
@ -121,7 +121,7 @@ import org.apache.commons.collections.AbstractTestObject;
|
|||||||
* @author Neil O'Toole
|
* @author Neil O'Toole
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractTestCollection extends AbstractTestObject {
|
public abstract class AbstractTestCollection<T> extends AbstractTestObject {
|
||||||
|
|
||||||
//
|
//
|
||||||
// NOTE:
|
// NOTE:
|
||||||
@ -140,7 +140,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
/**
|
/**
|
||||||
* A collection instance that will be used for testing.
|
* A collection instance that will be used for testing.
|
||||||
*/
|
*/
|
||||||
public Collection collection;
|
public Collection<T> collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirmed collection. This is an instance of a collection that is
|
* Confirmed collection. This is an instance of a collection that is
|
||||||
@ -150,7 +150,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
* collection, and then calling verify() to make sure your collection
|
* collection, and then calling verify() to make sure your collection
|
||||||
* still matches the confirmed collection.
|
* still matches the confirmed collection.
|
||||||
*/
|
*/
|
||||||
public Collection confirmed;
|
public Collection<T> confirmed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit constructor.
|
* JUnit constructor.
|
||||||
@ -262,7 +262,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
// copy each collection value into an array
|
// copy each collection value into an array
|
||||||
Object[] confirmedValues = new Object[confirmedSize];
|
Object[] confirmedValues = new Object[confirmedSize];
|
||||||
|
|
||||||
Iterator iter;
|
Iterator<T> iter;
|
||||||
|
|
||||||
iter = confirmed.iterator();
|
iter = confirmed.iterator();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@ -340,7 +340,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
*
|
*
|
||||||
* @return a confirmed empty collection
|
* @return a confirmed empty collection
|
||||||
*/
|
*/
|
||||||
public abstract Collection makeConfirmedCollection();
|
public abstract Collection<T> makeConfirmedCollection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a confirmed full collection.
|
* Returns a confirmed full collection.
|
||||||
@ -350,12 +350,12 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
*
|
*
|
||||||
* @return a confirmed full collection
|
* @return a confirmed full collection
|
||||||
*/
|
*/
|
||||||
public abstract Collection makeConfirmedFullCollection();
|
public abstract Collection<T> makeConfirmedFullCollection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new, empty {@link Collection} to be used for testing.
|
* Return a new, empty {@link Collection} to be used for testing.
|
||||||
*/
|
*/
|
||||||
public abstract Collection makeCollection();
|
public abstract Collection<T> makeCollection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a full collection to be used for testing. The collection
|
* Returns a full collection to be used for testing. The collection
|
||||||
@ -365,8 +365,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
* the results of {@link #getFullElements()}. Override this default
|
* the results of {@link #getFullElements()}. Override this default
|
||||||
* if your collection doesn't support addAll.
|
* if your collection doesn't support addAll.
|
||||||
*/
|
*/
|
||||||
public Collection makeFullCollection() {
|
public Collection<T> makeFullCollection() {
|
||||||
Collection c = makeCollection();
|
Collection<T> c = makeCollection();
|
||||||
c.addAll(Arrays.asList(getFullElements()));
|
c.addAll(Arrays.asList(getFullElements()));
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@ -381,10 +381,10 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
/**
|
/**
|
||||||
* Creates a new Map Entry that is independent of the first and the map.
|
* Creates a new Map Entry that is independent of the first and the map.
|
||||||
*/
|
*/
|
||||||
public Map.Entry cloneMapEntry(Map.Entry entry) {
|
public Map.Entry<T, T> cloneMapEntry(Map.Entry<T, T> entry) {
|
||||||
HashMap map = new HashMap();
|
HashMap<T, T> map = new HashMap<T, T>();
|
||||||
map.put(entry.getKey(), entry.getValue());
|
map.put(entry.getKey(), entry.getValue());
|
||||||
return (Map.Entry) map.entrySet().iterator().next();
|
return map.entrySet().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -398,14 +398,14 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
* override {@link #makeFullCollection()}, you <I>must</I> override
|
* override {@link #makeFullCollection()}, you <I>must</I> override
|
||||||
* this method to reflect the contents of a full collection.
|
* this method to reflect the contents of a full collection.
|
||||||
*/
|
*/
|
||||||
public Object[] getFullElements() {
|
public T[] getFullElements() {
|
||||||
if (isNullSupported()) {
|
if (isNullSupported()) {
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<T> list = new ArrayList<T>();
|
||||||
list.addAll(Arrays.asList(getFullNonNullElements()));
|
list.addAll(Arrays.asList(getFullNonNullElements()));
|
||||||
list.add(4, null);
|
list.add(4, null);
|
||||||
return list.toArray();
|
return (T[]) list.toArray();
|
||||||
} else {
|
} else {
|
||||||
return (Object[]) getFullNonNullElements().clone();
|
return getFullNonNullElements().clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
* to an empty or full collection, so if your collection restricts
|
* to an empty or full collection, so if your collection restricts
|
||||||
* certain kinds of elements, you should override this method.
|
* certain kinds of elements, you should override this method.
|
||||||
*/
|
*/
|
||||||
public Object[] getOtherElements() {
|
public T[] getOtherElements() {
|
||||||
return getOtherNonNullElements();
|
return getOtherNonNullElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,8 +431,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
* the results of this method if your collection does not support
|
* the results of this method if your collection does not support
|
||||||
* the null element.
|
* the null element.
|
||||||
*/
|
*/
|
||||||
public Object[] getFullNonNullElements() {
|
public T[] getFullNonNullElements() {
|
||||||
return new Object[] {
|
return (T[]) new Object[] {
|
||||||
new String(""),
|
new String(""),
|
||||||
new String("One"),
|
new String("One"),
|
||||||
new Integer(2),
|
new Integer(2),
|
||||||
@ -459,8 +459,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
* {@link #getOtherElements()}. Includes many objects
|
* {@link #getOtherElements()}. Includes many objects
|
||||||
* of different types.
|
* of different types.
|
||||||
*/
|
*/
|
||||||
public Object[] getOtherNonNullElements() {
|
public T[] getOtherNonNullElements() {
|
||||||
return new Object[] {
|
return (T[]) new Object[] {
|
||||||
new Integer(0),
|
new Integer(0),
|
||||||
new Float(0),
|
new Float(0),
|
||||||
new Double(0),
|
new Double(0),
|
||||||
@ -507,7 +507,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
public void testCollectionAdd() {
|
public void testCollectionAdd() {
|
||||||
if (!isAddSupported()) return;
|
if (!isAddSupported()) return;
|
||||||
|
|
||||||
Object[] elements = getFullElements();
|
T[] elements = getFullElements();
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
boolean r = collection.add(elements[i]);
|
boolean r = collection.add(elements[i]);
|
||||||
@ -539,7 +539,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
if (!isAddSupported()) return;
|
if (!isAddSupported()) return;
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
Object[] elements = getFullElements();
|
T[] elements = getFullElements();
|
||||||
boolean r = collection.addAll(Arrays.asList(elements));
|
boolean r = collection.addAll(Arrays.asList(elements));
|
||||||
confirmed.addAll(Arrays.asList(elements));
|
confirmed.addAll(Arrays.asList(elements));
|
||||||
verify();
|
verify();
|
||||||
@ -587,7 +587,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
try {
|
||||||
collection.add(new Object());
|
collection.add(getFullNonNullElements()[0]);
|
||||||
fail("Emtpy collection should not support add.");
|
fail("Emtpy collection should not support add.");
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -608,7 +608,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
collection.add(new Object());
|
collection.add(getFullNonNullElements()[0]);
|
||||||
fail("Full collection should not support add.");
|
fail("Full collection should not support add.");
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -692,7 +692,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
*/
|
*/
|
||||||
public void testCollectionContainsAll() {
|
public void testCollectionContainsAll() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
Collection col = new HashSet();
|
Collection<T> col = new HashSet<T>();
|
||||||
assertTrue("Every Collection should contain all elements of an " +
|
assertTrue("Every Collection should contain all elements of an " +
|
||||||
"empty Collection.", collection.containsAll(col));
|
"empty Collection.", collection.containsAll(col));
|
||||||
col.addAll(Arrays.asList(getOtherElements()));
|
col.addAll(Arrays.asList(getOtherElements()));
|
||||||
@ -723,7 +723,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
// make sure calls to "containsAll" don't change anything
|
// make sure calls to "containsAll" don't change anything
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
col = new ArrayList();
|
col = new ArrayList<T>();
|
||||||
col.addAll(Arrays.asList(getFullElements()));
|
col.addAll(Arrays.asList(getFullElements()));
|
||||||
col.addAll(Arrays.asList(getFullElements()));
|
col.addAll(Arrays.asList(getFullElements()));
|
||||||
assertTrue("Full collection should containAll duplicate full " +
|
assertTrue("Full collection should containAll duplicate full " +
|
||||||
@ -756,7 +756,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
*/
|
*/
|
||||||
public void testCollectionIterator() {
|
public void testCollectionIterator() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
Iterator it1 = collection.iterator();
|
Iterator<T> it1 = collection.iterator();
|
||||||
assertEquals("Iterator for empty Collection shouldn't have next.",
|
assertEquals("Iterator for empty Collection shouldn't have next.",
|
||||||
false, it1.hasNext());
|
false, it1.hasNext());
|
||||||
try {
|
try {
|
||||||
@ -778,10 +778,10 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
}
|
}
|
||||||
assertTrue("Iterator should be finished", !it1.hasNext());
|
assertTrue("Iterator should be finished", !it1.hasNext());
|
||||||
|
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<T> list = new ArrayList<T>();
|
||||||
it1 = collection.iterator();
|
it1 = collection.iterator();
|
||||||
for (int i = 0; i < collection.size(); i++) {
|
for (int i = 0; i < collection.size(); i++) {
|
||||||
Object next = it1.next();
|
T next = it1.next();
|
||||||
assertTrue("Collection should contain element returned by " +
|
assertTrue("Collection should contain element returned by " +
|
||||||
"its iterator", collection.contains(next));
|
"its iterator", collection.contains(next));
|
||||||
list.add(next);
|
list.add(next);
|
||||||
@ -814,7 +814,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
iter.hasNext();
|
iter.hasNext();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("New iterator.remove should raise IllegalState " +
|
fail("New iterator.remove should raise IllegalState " +
|
||||||
@ -826,7 +826,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
int size = collection.size();
|
int size = collection.size();
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Object o = iter.next();
|
Object o = iter.next();
|
||||||
// TreeMap reuses the Map Entry, so the verify below fails
|
// TreeMap reuses the Map Entry, so the verify below fails
|
||||||
@ -931,7 +931,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
assertTrue("Emtpy collection removeAll should return false for " +
|
assertTrue("Emtpy collection removeAll should return false for " +
|
||||||
"nonempty input",
|
"nonempty input",
|
||||||
!collection.removeAll(new ArrayList(collection)));
|
!collection.removeAll(new ArrayList<T>(collection)));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -945,8 +945,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Full collection removeAll should return true for full elements",
|
assertTrue("Full collection removeAll should return true for full elements",
|
||||||
collection.removeAll(new HashSet(collection)));
|
collection.removeAll(new HashSet<T>(collection)));
|
||||||
confirmed.removeAll(new HashSet(confirmed));
|
confirmed.removeAll(new HashSet<T>(confirmed));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -954,7 +954,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
int min = (getFullElements().length < 2 ? 0 : 2);
|
int min = (getFullElements().length < 2 ? 0 : 2);
|
||||||
int max = (getFullElements().length == 1 ? 1 :
|
int max = (getFullElements().length == 1 ? 1 :
|
||||||
(getFullElements().length <= 5 ? getFullElements().length - 1 : 5));
|
(getFullElements().length <= 5 ? getFullElements().length - 1 : 5));
|
||||||
Collection all = Arrays.asList(getFullElements()).subList(min, max);
|
Collection<T> all = Arrays.asList(getFullElements()).subList(min, max);
|
||||||
assertTrue("Full collection removeAll should work",
|
assertTrue("Full collection removeAll should work",
|
||||||
collection.removeAll(all));
|
collection.removeAll(all));
|
||||||
confirmed.removeAll(all);
|
confirmed.removeAll(all);
|
||||||
@ -962,7 +962,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
assertTrue("Collection should shrink after removeAll",
|
assertTrue("Collection should shrink after removeAll",
|
||||||
collection.size() < size);
|
collection.size() < size);
|
||||||
Iterator iter = all.iterator();
|
Iterator<T> iter = all.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
assertTrue("Collection shouldn't contain removed element",
|
assertTrue("Collection shouldn't contain removed element",
|
||||||
!collection.contains(iter.next()));
|
!collection.contains(iter.next()));
|
||||||
@ -977,8 +977,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) return;
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
List elements = Arrays.asList(getFullElements());
|
List<T> elements = Arrays.asList(getFullElements());
|
||||||
List other = Arrays.asList(getOtherElements());
|
List<T> other = Arrays.asList(getOtherElements());
|
||||||
|
|
||||||
assertTrue("Empty retainAll() should return false",
|
assertTrue("Empty retainAll() should return false",
|
||||||
!collection.retainAll(Collections.EMPTY_SET));
|
!collection.retainAll(Collections.EMPTY_SET));
|
||||||
@ -1018,7 +1018,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
confirmed.retainAll(elements.subList(min, max));
|
confirmed.retainAll(elements.subList(min, max));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
assertTrue("Collection only contains retained element",
|
assertTrue("Collection only contains retained element",
|
||||||
elements.subList(min, max).contains(iter.next()));
|
elements.subList(min, max).contains(iter.next()));
|
||||||
@ -1026,7 +1026,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
HashSet set = new HashSet(elements);
|
HashSet<T> set = new HashSet<T>(elements);
|
||||||
size = collection.size();
|
size = collection.size();
|
||||||
assertTrue("Collection shouldn't change from retainAll without " +
|
assertTrue("Collection shouldn't change from retainAll without " +
|
||||||
"duplicate elements", !collection.retainAll(set));
|
"duplicate elements", !collection.retainAll(set));
|
||||||
@ -1130,13 +1130,13 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
// Figure out if they're all the same class
|
// Figure out if they're all the same class
|
||||||
// TODO: It'd be nicer to detect a common superclass
|
// TODO: It'd be nicer to detect a common superclass
|
||||||
HashSet classes = new HashSet();
|
HashSet<Class<?>> classes = new HashSet<Class<?>>();
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
classes.add((array[i] == null) ? null : array[i].getClass());
|
classes.add((array[i] == null) ? null : array[i].getClass());
|
||||||
}
|
}
|
||||||
if (classes.size() > 1) return;
|
if (classes.size() > 1) return;
|
||||||
|
|
||||||
Class cl = (Class)classes.iterator().next();
|
Class<?> cl = classes.iterator().next();
|
||||||
if (Map.Entry.class.isAssignableFrom(cl)) { // check needed for protective cases like Predicated/Unmod map entrySet
|
if (Map.Entry.class.isAssignableFrom(cl)) { // check needed for protective cases like Predicated/Unmod map entrySet
|
||||||
cl = Map.Entry.class;
|
cl = Map.Entry.class;
|
||||||
}
|
}
|
||||||
@ -1207,7 +1207,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iterator = collection.iterator();
|
Iterator<T> iterator = collection.iterator();
|
||||||
iterator.next();
|
iterator.next();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
fail("iterator.remove should raise UnsupportedOperationException");
|
fail("iterator.remove should raise UnsupportedOperationException");
|
||||||
@ -1228,8 +1228,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
if (isAddSupported()) {
|
if (isAddSupported()) {
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
Object o = getOtherElements()[0];
|
T o = getOtherElements()[0];
|
||||||
collection.add(o);
|
collection.add(o);
|
||||||
confirmed.add(o);
|
confirmed.add(o);
|
||||||
iter.next();
|
iter.next();
|
||||||
@ -1241,7 +1241,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
collection.addAll(Arrays.asList(getOtherElements()));
|
collection.addAll(Arrays.asList(getOtherElements()));
|
||||||
confirmed.addAll(Arrays.asList(getOtherElements()));
|
confirmed.addAll(Arrays.asList(getOtherElements()));
|
||||||
iter.next();
|
iter.next();
|
||||||
@ -1256,7 +1256,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
collection.clear();
|
collection.clear();
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("next after clear should raise ConcurrentModification");
|
fail("next after clear should raise ConcurrentModification");
|
||||||
@ -1268,7 +1268,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
collection.remove(getFullElements()[0]);
|
collection.remove(getFullElements()[0]);
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("next after remove should raise ConcurrentModification");
|
fail("next after remove should raise ConcurrentModification");
|
||||||
@ -1278,8 +1278,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
List sublist = Arrays.asList(getFullElements()).subList(2,5);
|
List<T> sublist = Arrays.asList(getFullElements()).subList(2,5);
|
||||||
collection.removeAll(sublist);
|
collection.removeAll(sublist);
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("next after removeAll should raise ConcurrentModification");
|
fail("next after removeAll should raise ConcurrentModification");
|
||||||
@ -1289,8 +1289,8 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
try {
|
||||||
Iterator iter = collection.iterator();
|
Iterator<T> iter = collection.iterator();
|
||||||
List sublist = Arrays.asList(getFullElements()).subList(2,5);
|
List<T> sublist = Arrays.asList(getFullElements()).subList(2,5);
|
||||||
collection.retainAll(sublist);
|
collection.retainAll(sublist);
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("next after retainAll should raise ConcurrentModification");
|
fail("next after retainAll should raise ConcurrentModification");
|
||||||
|
@ -36,7 +36,7 @@ import org.apache.commons.collections.PredicateUtils;
|
|||||||
*
|
*
|
||||||
* @author Phil Steitz
|
* @author Phil Steitz
|
||||||
*/
|
*/
|
||||||
public class TestPredicatedCollection extends AbstractTestCollection {
|
public class TestPredicatedCollection extends AbstractTestCollection<Object> {
|
||||||
|
|
||||||
public TestPredicatedCollection(String name) {
|
public TestPredicatedCollection(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
@ -50,54 +50,53 @@ public class TestPredicatedCollection extends AbstractTestCollection {
|
|||||||
String[] testCaseName = { TestPredicatedCollection.class.getName()};
|
String[] testCaseName = { TestPredicatedCollection.class.getName()};
|
||||||
junit.textui.TestRunner.main(testCaseName);
|
junit.textui.TestRunner.main(testCaseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
protected Predicate<Object> truePredicate = PredicateUtils.truePredicate();
|
||||||
protected Predicate truePredicate = PredicateUtils.truePredicate();
|
|
||||||
|
protected Collection<Object> decorateCollection(
|
||||||
protected Collection decorateCollection(Collection collection,
|
Collection<Object> collection, Predicate<Object> predicate) {
|
||||||
Predicate predicate) {
|
|
||||||
return PredicatedCollection.decorate(collection, predicate);
|
return PredicatedCollection.decorate(collection, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeCollection() {
|
public Collection<Object> makeCollection() {
|
||||||
return decorateCollection(new ArrayList(), truePredicate);
|
return decorateCollection(new ArrayList<Object>(), truePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedCollection() {
|
public Collection<Object> makeConfirmedCollection() {
|
||||||
return new ArrayList();
|
return new ArrayList<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getFullElements() {
|
public Object[] getFullElements() {
|
||||||
return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
|
return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeFullCollection() {
|
public Collection<Object> makeFullCollection() {
|
||||||
List list = new ArrayList();
|
List<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return decorateCollection(list, truePredicate);
|
return decorateCollection(list, truePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedFullCollection() {
|
public Collection<Object> makeConfirmedFullCollection() {
|
||||||
List list = new ArrayList();
|
List<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
protected Predicate testPredicate =
|
protected Predicate<Object> testPredicate =
|
||||||
new Predicate() {
|
new Predicate<Object>() {
|
||||||
public boolean evaluate(Object o) {
|
public boolean evaluate(Object o) {
|
||||||
return o instanceof String;
|
return o instanceof String;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public Collection makeTestCollection() {
|
public Collection<Object> makeTestCollection() {
|
||||||
return decorateCollection(new ArrayList(), testPredicate);
|
return decorateCollection(new ArrayList<Object>(), testPredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
Collection c = makeTestCollection();
|
Collection<Object> c = makeTestCollection();
|
||||||
Integer i = new Integer(3);
|
Integer i = new Integer(3);
|
||||||
try {
|
try {
|
||||||
c.add(i);
|
c.add(i);
|
||||||
@ -110,8 +109,8 @@ public class TestPredicatedCollection extends AbstractTestCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIllegalAddAll() {
|
public void testIllegalAddAll() {
|
||||||
Collection c = makeTestCollection();
|
Collection<Object> c = makeTestCollection();
|
||||||
List elements = new ArrayList();
|
List<Object> elements = new ArrayList<Object>();
|
||||||
elements.add("one");
|
elements.add("one");
|
||||||
elements.add("two");
|
elements.add("two");
|
||||||
elements.add(new Integer(3));
|
elements.add(new Integer(3));
|
||||||
|
@ -33,7 +33,7 @@ import junit.framework.TestSuite;
|
|||||||
* @author Phil Steitz
|
* @author Phil Steitz
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class TestSynchronizedCollection extends AbstractTestCollection {
|
public class TestSynchronizedCollection extends AbstractTestCollection<Object> {
|
||||||
|
|
||||||
public TestSynchronizedCollection(String testName) {
|
public TestSynchronizedCollection(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
@ -49,17 +49,17 @@ public class TestSynchronizedCollection extends AbstractTestCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public Collection makeCollection() {
|
public Collection<Object> makeCollection() {
|
||||||
return SynchronizedCollection.decorate(new ArrayList());
|
return SynchronizedCollection.decorate(new ArrayList<Object>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedCollection() {
|
public Collection<Object> makeConfirmedCollection() {
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<Object> list = new ArrayList<Object>();
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedFullCollection() {
|
public Collection<Object> makeConfirmedFullCollection() {
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -36,16 +36,16 @@ import org.apache.commons.collections.TransformerUtils;
|
|||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class TestTransformedCollection extends AbstractTestCollection {
|
public class TestTransformedCollection extends AbstractTestCollection<Object> {
|
||||||
|
|
||||||
private static class StringToInteger implements Transformer {
|
private static class StringToInteger implements Transformer<Object, Object> {
|
||||||
public Object transform(Object input) {
|
public Object transform(Object input) {
|
||||||
return new Integer((String) input);
|
return new Integer((String) input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Transformer NOOP_TRANSFORMER = TransformerUtils.nopTransformer();
|
public static final Transformer<Object, Object> NOOP_TRANSFORMER = TransformerUtils.nopTransformer();
|
||||||
public static final Transformer STRING_TO_INTEGER_TRANSFORMER = new StringToInteger();
|
public static final Transformer<Object, Object> STRING_TO_INTEGER_TRANSFORMER = new StringToInteger();
|
||||||
|
|
||||||
public TestTransformedCollection(String testName) {
|
public TestTransformedCollection(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
@ -61,22 +61,22 @@ public class TestTransformedCollection extends AbstractTestCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public Collection makeConfirmedCollection() {
|
public Collection<Object> makeConfirmedCollection() {
|
||||||
return new ArrayList();
|
return new ArrayList<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedFullCollection() {
|
public Collection<Object> makeConfirmedFullCollection() {
|
||||||
List list = new ArrayList();
|
List<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeCollection() {
|
public Collection<Object> makeCollection() {
|
||||||
return TransformedCollection.decorate(new ArrayList(), NOOP_TRANSFORMER);
|
return TransformedCollection.decorate(new ArrayList<Object>(), NOOP_TRANSFORMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeFullCollection() {
|
public Collection<Object> makeFullCollection() {
|
||||||
List list = new ArrayList();
|
List<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return TransformedCollection.decorate(list, NOOP_TRANSFORMER);
|
return TransformedCollection.decorate(list, NOOP_TRANSFORMER);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ public class TestTransformedCollection extends AbstractTestCollection {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testTransformedCollection() {
|
public void testTransformedCollection() {
|
||||||
Collection coll = TransformedCollection.decorate(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER);
|
Collection<Object> coll = TransformedCollection.decorate(new ArrayList<Object>(), STRING_TO_INTEGER_TRANSFORMER);
|
||||||
assertEquals(0, coll.size());
|
assertEquals(0, coll.size());
|
||||||
Object[] els = getFullElements();
|
Object[] els = getFullElements();
|
||||||
for (int i = 0; i < els.length; i++) {
|
for (int i = 0; i < els.length; i++) {
|
||||||
|
@ -34,7 +34,7 @@ import junit.framework.TestSuite;
|
|||||||
* @author Phil Steitz
|
* @author Phil Steitz
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class TestUnmodifiableCollection extends AbstractTestCollection {
|
public class TestUnmodifiableCollection extends AbstractTestCollection<Object> {
|
||||||
|
|
||||||
public TestUnmodifiableCollection(String testName) {
|
public TestUnmodifiableCollection(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
@ -50,23 +50,23 @@ public class TestUnmodifiableCollection extends AbstractTestCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public Collection makeCollection() {
|
public Collection<Object> makeCollection() {
|
||||||
return UnmodifiableCollection.decorate(new ArrayList());
|
return UnmodifiableCollection.decorate(new ArrayList<Object>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeFullCollection() {
|
public Collection<Object> makeFullCollection() {
|
||||||
List list = new ArrayList();
|
List<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return UnmodifiableCollection.decorate(list);
|
return UnmodifiableCollection.decorate(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedCollection() {
|
public Collection<Object> makeConfirmedCollection() {
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<Object> list = new ArrayList<Object>();
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection makeConfirmedFullCollection() {
|
public Collection<Object> makeConfirmedFullCollection() {
|
||||||
ArrayList list = new ArrayList();
|
ArrayList<Object> list = new ArrayList<Object>();
|
||||||
list.addAll(Arrays.asList(getFullElements()));
|
list.addAll(Arrays.asList(getFullElements()));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user