You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/09/15 07:30:02 UTC
svn commit: r814997 [16/18] - in /commons/proper/collections/trunk/src:
java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/
java/org/apache/commons/collections/bidimap/
java/org/apache/commons/collections/buffer/ java/org/apac...
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java Tue Sep 15 05:29:56 2009
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -37,7 +38,7 @@
* @author Matthew Hawthorne
* @author Tom Dunham
*/
-public class TestSetUniqueList extends AbstractTestList {
+public class TestSetUniqueList<E> extends AbstractTestList<E> {
public static void main(String[] args) {
TestRunner.run(suite());
@@ -52,53 +53,54 @@
}
//-----------------------------------------------------------------------
- public List makeEmptyList() {
- return new SetUniqueList(new ArrayList(), new HashSet());
+ public List<E> makeObject() {
+ return new SetUniqueList<E>(new ArrayList<E>(), new HashSet<E>());
}
public void testListIteratorSet() {
// override to block
resetFull();
- ListIterator it = getList().listIterator();
+ ListIterator<E> it = getCollection().listIterator();
it.next();
try {
it.set(null);
fail();
} catch (UnsupportedOperationException ex) {}
}
-
- public Object[] getFullNonNullElements() {
+
+ @SuppressWarnings("unchecked")
+ public E[] getFullNonNullElements() {
// override to avoid duplicate "One"
- return new Object[] {
- new String(""),
- new String("One"),
- new Integer(2),
- "Three",
- new Integer(4),
- new Double(5),
- new Float(6),
- "Seven",
- "Eight",
- new String("Nine"),
- new Integer(10),
- new Short((short)11),
- new Long(12),
- "Thirteen",
- "14",
- "15",
- new Byte((byte)16)
+ return (E[]) new Object[] {
+ new String(""),
+ new String("One"),
+ new Integer(2),
+ "Three",
+ new Integer(4),
+ new Double(5),
+ new Float(6),
+ "Seven",
+ "Eight",
+ new String("Nine"),
+ new Integer(10),
+ new Short((short)11),
+ new Long(12),
+ "Thirteen",
+ "14",
+ "15",
+ new Byte((byte)16)
};
}
-
+
public void testListIteratorAdd() {
// override to cope with Set behaviour
resetEmpty();
- List list1 = getList();
- List list2 = getConfirmedList();
+ List<E> list1 = getCollection();
+ List<E> list2 = getConfirmed();
- Object[] elements = getOtherElements(); // changed here
- ListIterator iter1 = list1.listIterator();
- ListIterator iter2 = list2.listIterator();
+ E[] elements = getOtherElements(); // changed here
+ ListIterator<E> iter1 = list1.listIterator();
+ ListIterator<E> iter2 = list2.listIterator();
for (int i = 0; i < elements.length; i++) {
iter1.add(elements[i]);
@@ -107,8 +109,8 @@
}
resetFull();
- iter1 = getList().listIterator();
- iter2 = getConfirmedList().listIterator();
+ iter1 = getCollection().listIterator();
+ iter2 = getConfirmed().listIterator();
for (int i = 0; i < elements.length; i++) {
iter1.next();
iter2.next();
@@ -117,35 +119,36 @@
super.verify(); // changed here
}
}
-
+
public void testCollectionAddAll() {
// override for set behaviour
resetEmpty();
- Object[] elements = getFullElements();
- boolean r = collection.addAll(Arrays.asList(elements));
- confirmed.addAll(Arrays.asList(elements));
+ E[] elements = getFullElements();
+ boolean r = getCollection().addAll(Arrays.asList(elements));
+ getConfirmed().addAll(Arrays.asList(elements));
verify();
assertTrue("Empty collection should change after addAll", r);
for (int i = 0; i < elements.length; i++) {
assertTrue("Collection should contain added element",
- collection.contains(elements[i]));
+ getCollection().contains(elements[i]));
}
resetFull();
- int size = collection.size();
+ int size = getCollection().size();
elements = getOtherElements();
- r = collection.addAll(Arrays.asList(elements));
- confirmed.addAll(Arrays.asList(elements));
+ r = getCollection().addAll(Arrays.asList(elements));
+ getConfirmed().addAll(Arrays.asList(elements));
verify();
assertTrue("Full collection should change after addAll", r);
for (int i = 0; i < elements.length; i++) {
assertTrue("Full collection should contain added element " + i,
- collection.contains(elements[i]));
+ getCollection().contains(elements[i]));
}
- assertEquals("Size should increase after addAll",
- size + elements.length, collection.size());
+ assertEquals("Size should increase after addAll",
+ size + elements.length, getCollection().size());
}
+ // TODO: Generics
public void testIntCollectionAddAll() {
// make a SetUniqueList with one element
List list = new SetUniqueList(new ArrayList(), new HashSet());
@@ -155,7 +158,7 @@
// add two new unique elements at index 0
final Integer firstNewElement = new Integer(2);
final Integer secondNewElement = new Integer(3);
- collection = Arrays.asList(new Integer[] {firstNewElement, secondNewElement});
+ Collection collection = Arrays.asList(new Integer[] {firstNewElement, secondNewElement});
list.addAll(0, collection);
assertEquals("Unique elements should be added.", 3, list.size());
assertEquals("First new element should be at index 0", firstNewElement, list.get(0));
@@ -171,18 +174,19 @@
assertEquals("Third new element should be at index 0", thirdNewElement, list.get(0));
}
+ @SuppressWarnings("unchecked")
public void testListSetByIndex() {
// override for set behaviour
resetFull();
- int size = collection.size();
- getList().set(0, new Long(1000));
- assertEquals(size, collection.size());
-
- getList().set(2, new Long(1000));
- assertEquals(size - 1, collection.size());
- assertEquals(new Long(1000), getList().get(1)); // set into 2, but shifted down to 1
+ int size = getCollection().size();
+ getCollection().set(0, (E) new Long(1000));
+ assertEquals(size, getCollection().size());
+
+ getCollection().set(2, (E) new Long(1000));
+ assertEquals(size - 1, getCollection().size());
+ assertEquals(new Long(1000), getCollection().get(1)); // set into 2, but shifted down to 1
}
-
+
boolean extraVerify = true;
public void testCollectionIteratorRemove() {
try {
@@ -192,28 +196,29 @@
extraVerify = true;
}
}
-
+
+ @SuppressWarnings("unchecked")
public void verify() {
super.verify();
-
+
if (extraVerify) {
- int size = collection.size();
- getList().add(new Long(1000));
- assertEquals(size + 1, collection.size());
-
- getList().add(new Long(1000));
- assertEquals(size + 1, collection.size());
- assertEquals(new Long(1000), getList().get(size));
-
- getList().remove(size);
+ int size = getCollection().size();
+ getCollection().add((E) new Long(1000));
+ assertEquals(size + 1, getCollection().size());
+
+ getCollection().add((E) new Long(1000));
+ assertEquals(size + 1, getCollection().size());
+ assertEquals(new Long(1000), getCollection().get(size));
+
+ getCollection().remove(size);
}
}
-
+
//-----------------------------------------------------------------------
public void testFactory() {
- Integer[] array = new Integer[] {new Integer(1), new Integer(2), new Integer(1)};
- ArrayList list = new ArrayList(Arrays.asList(array));
- final SetUniqueList lset = SetUniqueList.decorate(list);
+ Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(1) };
+ ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(array));
+ final SetUniqueList<Integer> lset = SetUniqueList.decorate(list);
assertEquals("Duplicate element was added.", 2, lset.size());
assertEquals(new Integer(1), lset.get(0));
@@ -222,36 +227,39 @@
assertEquals(new Integer(2), list.get(1));
}
+ @SuppressWarnings("unchecked")
public void testAdd() {
- final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet());
+ final SetUniqueList<E> lset = new SetUniqueList<E>(new ArrayList<E>(), new HashSet<E>());
// Duplicate element
- final Object obj = new Integer(1);
+ final E obj = (E) new Integer(1);
lset.add(obj);
lset.add(obj);
assertEquals("Duplicate element was added.", 1, lset.size());
// Unique element
- lset.add(new Integer(2));
+ lset.add((E) new Integer(2));
assertEquals("Unique element was not added.", 2, lset.size());
}
+ @SuppressWarnings("unchecked")
public void testAddAll() {
- final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet());
+ final SetUniqueList<E> lset = new SetUniqueList<E>(new ArrayList<E>(), new HashSet<E>());
lset.addAll(
- Arrays.asList(new Integer[] { new Integer(1), new Integer(1)}));
+ Arrays.asList((E[]) new Integer[] { new Integer(1), new Integer(1)}));
assertEquals("Duplicate element was added.", 1, lset.size());
}
+ @SuppressWarnings("unchecked")
public void testSet() {
- final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet());
+ final SetUniqueList<E> lset = new SetUniqueList<E>(new ArrayList<E>(), new HashSet<E>());
// Duplicate element
- final Object obj1 = new Integer(1);
- final Object obj2 = new Integer(2);
- final Object obj3 = new Integer(3);
+ final E obj1 = (E) new Integer(1);
+ final E obj2 = (E) new Integer(2);
+ final E obj3 = (E) new Integer(3);
lset.add(obj1);
lset.add(obj2);
@@ -283,16 +291,17 @@
assertSame(obj1, lset.get(0));
}
+ @SuppressWarnings("unchecked")
public void testListIterator() {
- final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet());
+ final SetUniqueList<E> lset = new SetUniqueList<E>(new ArrayList<E>(), new HashSet<E>());
- final Object obj1 = new Integer(1);
- final Object obj2 = new Integer(2);
+ final E obj1 = (E) new Integer(1);
+ final E obj2 = (E) new Integer(2);
lset.add(obj1);
lset.add(obj2);
// Attempts to add a duplicate object
- for (final ListIterator it = lset.listIterator(); it.hasNext();) {
+ for (final ListIterator<E> it = lset.listIterator(); it.hasNext();) {
it.next();
if (!it.hasNext()) {
@@ -304,36 +313,39 @@
assertEquals("Duplicate element was added", 2, lset.size());
}
+ @SuppressWarnings("unchecked")
public void testUniqueListReInsert() {
- List l = SetUniqueList.decorate(new LinkedList());
- l.add(new Object());
- l.add(new Object());
-
- Object a = l.get(0);
-
+ List<E> l = SetUniqueList.decorate(new LinkedList<E>());
+ l.add((E) new Object());
+ l.add((E) new Object());
+
+ E a = l.get(0);
+
// duplicate is removed
- l.set(0, l.get(1));
+ l.set(0, l.get(1));
assertEquals(1, l.size());
-
- // old object is added back in
- l.add(1, a);
+
+ // old object is added back in
+ l.add(1, a);
assertEquals(2, l.size());
}
-
+
+ @SuppressWarnings("unchecked")
public void testUniqueListDoubleInsert() {
- List l = SetUniqueList.decorate(new LinkedList());
- l.add(new Object());
- l.add(new Object());
-
+ List<E> l = SetUniqueList.decorate(new LinkedList<E>());
+ l.add((E) new Object());
+ l.add((E) new Object());
+
// duplicate is removed
- l.set(0, l.get(1));
+ l.set(0, l.get(1));
assertEquals(1, l.size());
-
+
// duplicate should be removed again
l.add(1, l.get(0));
assertEquals(1, l.size());
}
+ @SuppressWarnings("unchecked")
public void testSetDownwardsInList() {
/*
* Checks the following semantics
@@ -341,19 +353,19 @@
* set(0,b): [b]->a
* So UniqList contains [b] and a is returned
*/
- ArrayList l = new ArrayList();
- HashSet s = new HashSet();
- final SetUniqueList ul = new SetUniqueList(l, s);
+ ArrayList<E> l = new ArrayList<E>();
+ HashSet<E> s = new HashSet<E>();
+ final SetUniqueList<E> ul = new SetUniqueList<E>(l, s);
- Object a = new Object();
- Object b = new Object();
+ E a = (E) new Object();
+ E b = (E) new Object();
ul.add(a);
ul.add(b);
assertEquals(a, l.get(0));
assertEquals(b, l.get(1));
- assertTrue(s.contains(a));
+ assertTrue(s.contains(a));
assertTrue(s.contains(b));
-
+
assertEquals(a, ul.set(0, b));
assertEquals(1, s.size());
assertEquals(1, l.size());
@@ -362,6 +374,7 @@
assertFalse(s.contains(a));
}
+ @SuppressWarnings("unchecked")
public void testSetInBiggerList() {
/*
* Checks the following semantics
@@ -369,13 +382,13 @@
* set(0,b): [b,c]->a
* So UniqList contains [b,c] and a is returned
*/
- ArrayList l = new ArrayList();
- HashSet s = new HashSet();
- final SetUniqueList ul = new SetUniqueList(l, s);
-
- Object a = new Object();
- Object b = new Object();
- Object c = new Object();
+ ArrayList<E> l = new ArrayList<E>();
+ HashSet<E> s = new HashSet<E>();
+ final SetUniqueList<E> ul = new SetUniqueList<E>(l, s);
+
+ E a = (E) new Object();
+ E b = (E) new Object();
+ E c = (E) new Object();
ul.add(a);
ul.add(b);
@@ -383,10 +396,10 @@
assertEquals(a, l.get(0));
assertEquals(b, l.get(1));
assertEquals(c, l.get(2));
- assertTrue(s.contains(a));
+ assertTrue(s.contains(a));
assertTrue(s.contains(b));
assertTrue(s.contains(c));
-
+
assertEquals(a, ul.set(0, b));
assertEquals(2, s.size());
assertEquals(2, l.size());
@@ -395,8 +408,9 @@
assertFalse(s.contains(a));
assertTrue(s.contains(b));
assertTrue(s.contains(c));
- }
+ }
+ @SuppressWarnings("unchecked")
public void testSetUpwardsInList() {
/*
* Checks the following semantics
@@ -404,13 +418,13 @@
* set(1,a): [a,c]->b
* So UniqList contains [a,c] and b is returned
*/
- ArrayList l = new ArrayList();
- HashSet s = new HashSet();
- final SetUniqueList ul = new SetUniqueList(l, s);
-
- Object a = new String("A");
- Object b = new String("B");
- Object c = new String("C");
+ ArrayList<E> l = new ArrayList<E>();
+ HashSet<E> s = new HashSet<E>();
+ final SetUniqueList<E> ul = new SetUniqueList<E>(l, s);
+
+ E a = (E) new String("A");
+ E b = (E) new String("B");
+ E c = (E) new String("C");
ul.add(a);
ul.add(b);
@@ -418,10 +432,10 @@
assertEquals(a, l.get(0));
assertEquals(b, l.get(1));
assertEquals(c, l.get(2));
- assertTrue(s.contains(a));
+ assertTrue(s.contains(a));
assertTrue(s.contains(b));
assertTrue(s.contains(c));
-
+
assertEquals(b, ul.set(1, a));
assertEquals(2, s.size());
assertEquals(2, l.size());
@@ -444,6 +458,7 @@
// writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/SetUniqueList.fullCollection.version3.1.obj");
// }
+ // TODO: Generics
public void testCollections304() {
List list = new LinkedList();
SetUniqueList decoratedList = SetUniqueList.decorate(list);
@@ -471,33 +486,34 @@
assertEquals(4, decoratedList.size());
}
+ @SuppressWarnings("unchecked")
public void testCollections307() {
- List list = new ArrayList();
- List uniqueList = SetUniqueList.decorate(list);
+ List<E> list = new ArrayList<E>();
+ List<E> uniqueList = SetUniqueList.decorate(list);
String hello = "Hello";
String world = "World";
- uniqueList.add(hello);
- uniqueList.add(world);
+ uniqueList.add((E) hello);
+ uniqueList.add((E) world);
- List subList = list.subList(0, 0);
- List subUniqueList = uniqueList.subList(0, 0);
+ List<E> subList = list.subList(0, 0);
+ List<E> subUniqueList = uniqueList.subList(0, 0);
assertFalse(subList.contains(world)); // passes
assertFalse(subUniqueList.contains(world)); // fails
- List worldList = new ArrayList();
- worldList.add(world);
+ List<E> worldList = new ArrayList<E>();
+ worldList.add((E) world);
assertFalse(subList.contains("World")); // passes
assertFalse(subUniqueList.contains("World")); // fails
- // repeat the test with a different class than HashSet;
+ // repeat the test with a different class than HashSet;
// which means subclassing SetUniqueList below
- list = new ArrayList();
- uniqueList = new SetUniqueList307(list, new java.util.TreeSet());
+ list = new ArrayList<E>();
+ uniqueList = new SetUniqueList307(list, new java.util.TreeSet<E>());
- uniqueList.add(hello);
- uniqueList.add(world);
+ uniqueList.add((E) hello);
+ uniqueList.add((E) world);
subList = list.subList(0, 0);
subUniqueList = uniqueList.subList(0, 0);
@@ -505,14 +521,15 @@
assertFalse(subList.contains(world)); // passes
assertFalse(subUniqueList.contains(world)); // fails
- worldList = new ArrayList();
- worldList.add(world);
+ worldList = new ArrayList<E>();
+ worldList.add((E) world);
assertFalse(subList.contains("World")); // passes
assertFalse(subUniqueList.contains("World")); // fails
}
- class SetUniqueList307 extends SetUniqueList {
- public SetUniqueList307(List list, Set set) {
+ @SuppressWarnings("serial")
+ class SetUniqueList307 extends SetUniqueList<E> {
+ public SetUniqueList307(List<E> list, Set<E> set) {
super(list, set);
}
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSynchronizedList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSynchronizedList.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSynchronizedList.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSynchronizedList.java Tue Sep 15 05:29:56 2009
@@ -17,7 +17,6 @@
package org.apache.commons.collections.list;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import junit.framework.Test;
@@ -32,8 +31,8 @@
*
* @author Stephen Colebourne
*/
-public class TestSynchronizedList extends AbstractTestList {
-
+public class TestSynchronizedList<E> extends AbstractTestList<E> {
+
public TestSynchronizedList(String testName) {
super(testName);
}
@@ -47,12 +46,12 @@
junit.textui.TestRunner.main(testCaseName);
}
- public Collection makeConfirmedCollection() {
- return new ArrayList();
+ public List<E> makeConfirmedCollection() {
+ return new ArrayList<E>();
}
- public List makeEmptyList() {
- return SynchronizedList.decorate(new ArrayList());
+ public List<E> makeObject() {
+ return SynchronizedList.decorate(new ArrayList<E>());
}
public String getCompatibilityVersion() {
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTransformedList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTransformedList.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTransformedList.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTransformedList.java Tue Sep 15 05:29:56 2009
@@ -18,13 +18,13 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.collection.TestTransformedCollection;
/**
@@ -36,8 +36,8 @@
*
* @author Stephen Colebourne
*/
-public class TestTransformedList extends AbstractTestList {
-
+public class TestTransformedList<E> extends AbstractTestList<E> {
+
public TestTransformedList(String testName) {
super(testName);
}
@@ -51,67 +51,70 @@
junit.textui.TestRunner.main(testCaseName);
}
- public Collection makeConfirmedCollection() {
- return new ArrayList();
+ public List<E> makeConfirmedCollection() {
+ return new ArrayList<E>();
}
- public Collection makeConfirmedFullCollection() {
- List list = new ArrayList();
+ public List<E> makeConfirmedFullCollection() {
+ List<E> list = new ArrayList<E>();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
-
- public List makeEmptyList() {
- return TransformedList.decorate(new ArrayList(), TestTransformedCollection.NOOP_TRANSFORMER);
+
+ @SuppressWarnings("unchecked")
+ public List<E> makeObject() {
+ return TransformedList.decorate(new ArrayList<E>(), (Transformer<E, E>) TestTransformedCollection.NOOP_TRANSFORMER);
}
- public List makeFullList() {
- List list = new ArrayList();
+ @SuppressWarnings("unchecked")
+ public List<E> makeFullCollection() {
+ List<E> list = new ArrayList<E>();
list.addAll(Arrays.asList(getFullElements()));
- return TransformedList.decorate(list, TestTransformedCollection.NOOP_TRANSFORMER);
+ return TransformedList.decorate(list, (Transformer<E, E>) TestTransformedCollection.NOOP_TRANSFORMER);
}
-
+
+ @SuppressWarnings("unchecked")
public void testTransformedList() {
- List list = TransformedList.decorate(new ArrayList(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
+ List<E> list = TransformedList.decorate(new ArrayList<E>(), (Transformer<E, E>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, list.size());
- Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
+ E[] els = (E[]) new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
list.add(els[i]);
assertEquals(i + 1, list.size());
assertEquals(true, list.contains(new Integer((String) els[i])));
assertEquals(false, list.contains(els[i]));
}
-
+
assertEquals(false, list.remove(els[0]));
assertEquals(true, list.remove(new Integer((String) els[0])));
-
+
list.clear();
for (int i = 0; i < els.length; i++) {
list.add(0, els[i]);
assertEquals(i + 1, list.size());
assertEquals(new Integer((String) els[i]), list.get(0));
}
-
- list.set(0, "22");
+
+ list.set(0, (E) "22");
assertEquals(new Integer(22), list.get(0));
-
- ListIterator it = list.listIterator();
+
+ ListIterator<E> it = list.listIterator();
it.next();
- it.set("33");
+ it.set((E) "33");
assertEquals(new Integer(33), list.get(0));
- it.add("44");
+ it.add((E) "44");
assertEquals(new Integer(44), list.get(1));
-
- List adds = new ArrayList();
- adds.add("1");
- adds.add("2");
+
+ List<E> adds = new ArrayList<E>();
+ adds.add((E) "1");
+ adds.add((E) "2");
list.clear();
list.addAll(adds);
assertEquals(new Integer(1), list.get(0));
assertEquals(new Integer(2), list.get(1));
-
+
adds.clear();
- adds.add("3");
+ adds.add((E) "3");
list.addAll(1, adds);
assertEquals(new Integer(1), list.get(0));
assertEquals(new Integer(3), list.get(1));
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestUnmodifiableList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestUnmodifiableList.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestUnmodifiableList.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestUnmodifiableList.java Tue Sep 15 05:29:56 2009
@@ -25,7 +25,7 @@
import junit.framework.TestSuite;
/**
- * Extension of {@link AbstractTestList} for exercising the
+ * Extension of {@link AbstractTestList} for exercising the
* {@link UnmodifiableList} implementation.
*
* @since Commons Collections 3.0
@@ -33,72 +33,74 @@
*
* @author Phil Steitz
*/
-public class TestUnmodifiableList extends AbstractTestList {
-
+public class TestUnmodifiableList<E> extends AbstractTestList<E> {
+
public TestUnmodifiableList(String testName) {
super(testName);
}
-
+
public static Test suite() {
return new TestSuite(TestUnmodifiableList.class);
}
-
+
public static void main(String args[]) {
String[] testCaseName = { TestUnmodifiableList.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
- //-----------------------------------------------------------------------
- public List makeEmptyList() {
- return UnmodifiableList.decorate(new ArrayList());
- }
-
- public List makeFullList() {
- ArrayList list = new ArrayList();
+ //-----------------------------------------------------------------------
+ public UnmodifiableList<E> makeObject() {
+ return new UnmodifiableList<E>(new ArrayList<E>());
+ }
+
+ public UnmodifiableList<E> makeFullCollection() {
+ ArrayList<E> list = new ArrayList<E>();
list.addAll(Arrays.asList(getFullElements()));
- return UnmodifiableList.decorate(list);
+ return new UnmodifiableList<E>(list);
}
-
+
public boolean isSetSupported() {
return false;
}
-
+
public boolean isAddSupported() {
return false;
}
-
+
public boolean isRemoveSupported() {
return false;
}
-
- //-----------------------------------------------------------------------
- protected UnmodifiableList list = null;
- protected ArrayList array = null;
-
+
+ //-----------------------------------------------------------------------
+ protected UnmodifiableList<E> list;
+ protected ArrayList<E> array;
+
+ @SuppressWarnings("unchecked")
protected void setupList() {
- list = (UnmodifiableList) makeFullList();
- array = new ArrayList();
- array.add(new Integer(1));
+ list = makeFullCollection();
+ array = new ArrayList<E>();
+ array.add((E) new Integer(1));
}
-
- /**
+
+ /**
* Verify that base list and sublists are not modifiable
*/
public void testUnmodifiable() {
setupList();
- verifyUnmodifiable(list);
+ verifyUnmodifiable(list);
verifyUnmodifiable(list.subList(0, 2));
- }
-
- protected void verifyUnmodifiable(List list) {
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void verifyUnmodifiable(List<E> list) {
try {
- list.add(0, new Integer(0));
+ list.add(0, (E) new Integer(0));
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
- }
+ }
try {
- list.add(new Integer(0));
+ list.add((E) new Integer(0));
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
@@ -146,21 +148,21 @@
// expected
}
try {
- list.set(0, new Integer(0));
+ list.set(0, (E) new Integer(0));
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
}
-
+
/**
* Verify that iterator is not modifiable
*/
public void testUnmodifiableIterator() {
setupList();
- Iterator iterator = list.iterator();
+ Iterator<E> iterator = list.iterator();
try {
- Object obj = iterator.next();
+ iterator.next();
iterator.remove();
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java Tue Sep 15 05:29:56 2009
@@ -26,8 +26,8 @@
import java.util.TreeMap;
import org.apache.commons.collections.BulkTest;
-import org.apache.commons.collections.MapIterator;
import org.apache.commons.collections.OrderedMap;
+import org.apache.commons.collections.OrderedMapIterator;
import org.apache.commons.collections.comparators.NullComparator;
import org.apache.commons.collections.iterators.AbstractTestOrderedMapIterator;
@@ -38,93 +38,108 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractTestOrderedMap extends AbstractTestIterableMap {
+public abstract class AbstractTestOrderedMap<K, V> extends AbstractTestIterableMap<K, V> {
/**
* JUnit constructor.
- *
+ *
* @param testName the test name
*/
public AbstractTestOrderedMap(String testName) {
super(testName);
}
-
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract OrderedMap<K, V> makeObject();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public OrderedMap<K, V> makeFullMap() {
+ return (OrderedMap<K, V>) super.makeFullMap();
+ }
+
//-----------------------------------------------------------------------
/**
* OrderedMap uses TreeMap as its known comparison.
- *
+ *
* @return a map that is known to be valid
*/
- public Map makeConfirmedMap() {
- return new TreeMap(new NullComparator());
+ public Map<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>(new NullComparator<K>());
}
-
+
/**
* The only confirmed collection we have that is ordered is the sorted one.
* Thus, sort the keys.
*/
- public Object[] getSampleKeys() {
- List list = new ArrayList(Arrays.asList(super.getSampleKeys()));
- Collections.sort(list, new NullComparator());
- return list.toArray();
+ @SuppressWarnings("unchecked")
+ public K[] getSampleKeys() {
+ List<K> list = new ArrayList<K>(Arrays.asList(super.getSampleKeys()));
+ Collections.sort(list, new NullComparator<K>());
+ return (K[]) list.toArray();
}
//-----------------------------------------------------------------------
public void testFirstKey() {
resetEmpty();
- OrderedMap ordered = (OrderedMap) map;
+ OrderedMap<K, V> ordered = getMap();
try {
ordered.firstKey();
fail();
} catch (NoSuchElementException ex) {}
-
+
resetFull();
- ordered = (OrderedMap) map;
- Object confirmedFirst = confirmed.keySet().iterator().next();
+ ordered = getMap();
+ K confirmedFirst = confirmed.keySet().iterator().next();
assertEquals(confirmedFirst, ordered.firstKey());
}
-
+
public void testLastKey() {
resetEmpty();
- OrderedMap ordered = (OrderedMap) map;
+ OrderedMap<K, V> ordered = getMap();
try {
ordered.lastKey();
fail();
} catch (NoSuchElementException ex) {}
-
+
resetFull();
- ordered = (OrderedMap) map;
- Object confirmedLast = null;
- for (Iterator it = confirmed.keySet().iterator(); it.hasNext();) {
+ ordered = getMap();
+ K confirmedLast = null;
+ for (Iterator<K> it = confirmed.keySet().iterator(); it.hasNext();) {
confirmedLast = it.next();
}
assertEquals(confirmedLast, ordered.lastKey());
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
public void testNextKey() {
resetEmpty();
- OrderedMap ordered = (OrderedMap) map;
+ OrderedMap<K, V> ordered = getMap();
assertEquals(null, ordered.nextKey(getOtherKeys()[0]));
- if (isAllowNullKey() == false) {
+ if (!isAllowNullKey()) {
try {
assertEquals(null, ordered.nextKey(null)); // this is allowed too
} catch (NullPointerException ex) {}
} else {
assertEquals(null, ordered.nextKey(null));
}
-
+
resetFull();
- ordered = (OrderedMap) map;
- Iterator it = confirmed.keySet().iterator();
- Object confirmedLast = it.next();
+ ordered = getMap();
+ Iterator<K> it = confirmed.keySet().iterator();
+ K confirmedLast = it.next();
while (it.hasNext()) {
- Object confirmedObject = it.next();
+ K confirmedObject = it.next();
assertEquals(confirmedObject, ordered.nextKey(confirmedLast));
confirmedLast = confirmedObject;
}
assertEquals(null, ordered.nextKey(confirmedLast));
-
+
if (isAllowNullKey() == false) {
try {
ordered.nextKey(null);
@@ -134,10 +149,10 @@
assertEquals(null, ordered.nextKey(null));
}
}
-
+
public void testPreviousKey() {
resetEmpty();
- OrderedMap ordered = (OrderedMap) map;
+ OrderedMap<K, V> ordered = getMap();
assertEquals(null, ordered.previousKey(getOtherKeys()[0]));
if (isAllowNullKey() == false) {
try {
@@ -146,20 +161,20 @@
} else {
assertEquals(null, ordered.previousKey(null));
}
-
+
resetFull();
- ordered = (OrderedMap) map;
- List list = new ArrayList(confirmed.keySet());
+ ordered = getMap();
+ List<K> list = new ArrayList<K>(confirmed.keySet());
Collections.reverse(list);
- Iterator it = list.iterator();
- Object confirmedLast = it.next();
+ Iterator<K> it = list.iterator();
+ K confirmedLast = it.next();
while (it.hasNext()) {
- Object confirmedObject = it.next();
+ K confirmedObject = it.next();
assertEquals(confirmedObject, ordered.previousKey(confirmedLast));
confirmedLast = confirmedObject;
}
assertEquals(null, ordered.previousKey(confirmedLast));
-
+
if (isAllowNullKey() == false) {
try {
ordered.previousKey(null);
@@ -171,17 +186,17 @@
}
}
}
-
+
//-----------------------------------------------------------------------
public BulkTest bulkTestOrderedMapIterator() {
return new InnerTestOrderedMapIterator();
}
-
- public class InnerTestOrderedMapIterator extends AbstractTestOrderedMapIterator {
+
+ public class InnerTestOrderedMapIterator extends AbstractTestOrderedMapIterator<K, V> {
public InnerTestOrderedMapIterator() {
super("InnerTestOrderedMapIterator");
}
-
+
public boolean supportsRemove() {
return AbstractTestOrderedMap.this.isRemoveSupported();
}
@@ -189,35 +204,42 @@
public boolean isGetStructuralModify() {
return AbstractTestOrderedMap.this.isGetStructuralModify();
}
-
+
public boolean supportsSetValue() {
return AbstractTestOrderedMap.this.isSetValueSupported();
}
- public MapIterator makeEmptyMapIterator() {
+ public OrderedMapIterator<K, V> makeEmptyIterator() {
resetEmpty();
- return ((OrderedMap) AbstractTestOrderedMap.this.map).orderedMapIterator();
+ return AbstractTestOrderedMap.this.getMap().mapIterator();
}
- public MapIterator makeFullMapIterator() {
+ public OrderedMapIterator<K, V> makeObject() {
resetFull();
- return ((OrderedMap) AbstractTestOrderedMap.this.map).orderedMapIterator();
+ return AbstractTestOrderedMap.this.getMap().mapIterator();
}
-
- public Map getMap() {
+
+ public OrderedMap<K, V> getMap() {
// assumes makeFullMapIterator() called first
- return AbstractTestOrderedMap.this.map;
+ return AbstractTestOrderedMap.this.getMap();
}
-
- public Map getConfirmedMap() {
+
+ public Map<K, V> getConfirmedMap() {
// assumes makeFullMapIterator() called first
- return AbstractTestOrderedMap.this.confirmed;
+ return AbstractTestOrderedMap.this.getConfirmed();
}
-
+
public void verify() {
super.verify();
AbstractTestOrderedMap.this.verify();
}
}
-
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public OrderedMap<K, V> getMap() {
+ return (OrderedMap<K, V>) super.getMap();
+ }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java Tue Sep 15 05:29:56 2009
@@ -33,21 +33,21 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractTestSortedMap extends AbstractTestMap {
+public abstract class AbstractTestSortedMap<K, V> extends AbstractTestMap<K, V> {
/**
* JUnit constructor.
- *
+ *
* @param testName the test name
*/
public AbstractTestSortedMap(String testName) {
super(testName);
}
-
+
//-----------------------------------------------------------------------
/**
* Can't sort null keys.
- *
+ *
* @return false
*/
public boolean isAllowNullKey() {
@@ -56,53 +56,67 @@
/**
* SortedMap uses TreeMap as its known comparison.
- *
+ *
* @return a map that is known to be valid
*/
- public Map makeConfirmedMap() {
- return new TreeMap();
+ public SortedMap<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>();
}
//-----------------------------------------------------------------------
public void testComparator() {
- SortedMap sm = (SortedMap) makeFullMap();
+// SortedMap<K, V> sm = makeFullMap();
// no tests I can think of
}
-
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract SortedMap<K, V> makeObject();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SortedMap<K, V> makeFullMap() {
+ return (SortedMap<K, V>) super.makeFullMap();
+ }
+
public void testFirstKey() {
- SortedMap sm = (SortedMap) makeFullMap();
+ SortedMap<K, V> sm = makeFullMap();
assertSame(sm.keySet().iterator().next(), sm.firstKey());
}
-
+
public void testLastKey() {
- SortedMap sm = (SortedMap) makeFullMap();
- Object obj = null;
- for (Iterator it = sm.keySet().iterator(); it.hasNext();) {
- obj = (Object) it.next();
+ SortedMap<K, V> sm = makeFullMap();
+ K obj = null;
+ for (Iterator<K> it = sm.keySet().iterator(); it.hasNext();) {
+ obj = it.next();
}
assertSame(obj, sm.lastKey());
}
-
- //-----------------------------------------------------------------------
+
+ //-----------------------------------------------------------------------
public BulkTest bulkTestHeadMap() {
- return new TestHeadMap(this);
+ return new TestHeadMap<K, V>(this);
}
public BulkTest bulkTestTailMap() {
- return new TestTailMap(this);
+ return new TestTailMap<K, V>(this);
}
public BulkTest bulkTestSubMap() {
- return new TestSubMap(this);
+ return new TestSubMap<K, V>(this);
}
- public static abstract class TestViewMap extends AbstractTestSortedMap {
- protected final AbstractTestMap main;
- protected final List subSortedKeys = new ArrayList();
- protected final List subSortedValues = new ArrayList();
- protected final List subSortedNewValues = new ArrayList();
-
- public TestViewMap(String name, AbstractTestMap main) {
+ public static abstract class TestViewMap <K, V> extends AbstractTestSortedMap<K, V> {
+ protected final AbstractTestMap<K, V> main;
+ protected final List<K> subSortedKeys = new ArrayList<K>();
+ protected final List<V> subSortedValues = new ArrayList<V>();
+ protected final List<V> subSortedNewValues = new ArrayList<V>();
+
+ public TestViewMap(String name, AbstractTestMap<K, V> main) {
super(name);
this.main = main;
}
@@ -130,17 +144,20 @@
public BulkTest bulkTestSubMap() {
return null; // block infinite recursion
}
-
- public Object[] getSampleKeys() {
- return subSortedKeys.toArray();
- }
- public Object[] getSampleValues() {
- return subSortedValues.toArray();
- }
- public Object[] getNewSampleValues() {
- return subSortedNewValues.toArray();
+
+ @SuppressWarnings("unchecked")
+ public K[] getSampleKeys() {
+ return (K[]) subSortedKeys.toArray();
+ }
+ @SuppressWarnings("unchecked")
+ public V[] getSampleValues() {
+ return (V[]) subSortedValues.toArray();
+ }
+ @SuppressWarnings("unchecked")
+ public V[] getNewSampleValues() {
+ return (V[]) subSortedNewValues.toArray();
}
-
+
public boolean isAllowNullKey() {
return main.isAllowNullKey();
}
@@ -176,16 +193,16 @@
// super.testFullMapCompatibility();
// }
}
-
- public static class TestHeadMap extends TestViewMap {
+
+ public static class TestHeadMap<K, V> extends TestViewMap<K, V> {
static final int SUBSIZE = 6;
- final Object toKey;
-
- public TestHeadMap(AbstractTestMap main) {
+ final K toKey;
+
+ public TestHeadMap(AbstractTestMap<K, V> main) {
super("SortedMap.HeadMap", main);
- SortedMap sm = (SortedMap) main.makeFullMap();
- for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map<K, V> sm = main.makeFullMap();
+ for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue());
}
@@ -194,18 +211,18 @@
this.subSortedValues.subList(SUBSIZE, this.subSortedValues.size()).clear();
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(0, SUBSIZE));
}
- public Map makeEmptyMap() {
+ public SortedMap<K, V> makeObject() {
// done this way so toKey is correctly set in the returned map
- return ((SortedMap) main.makeEmptyMap()).headMap(toKey);
+ return ((SortedMap<K, V>) main.makeObject()).headMap(toKey);
}
- public Map makeFullMap() {
- return ((SortedMap) main.makeFullMap()).headMap(toKey);
+ public SortedMap<K, V> makeFullMap() {
+ return ((SortedMap<K, V>) main.makeFullMap()).headMap(toKey);
}
public void testHeadMapOutOfRange() {
if (isPutAddSupported() == false) return;
resetEmpty();
try {
- ((SortedMap) map).put(toKey, subSortedValues.get(0));
+ getMap().put(toKey, subSortedValues.get(0));
fail();
} catch (IllegalArgumentException ex) {}
verify();
@@ -225,17 +242,17 @@
// "D:/dev/collections/data/test/FixedSizeSortedMap.fullCollection.version3.1.HeadMapView.obj");
// }
}
-
- public static class TestTailMap extends TestViewMap {
+
+ public static class TestTailMap <K, V> extends TestViewMap<K, V> {
static final int SUBSIZE = 6;
- final Object fromKey;
- final Object invalidKey;
-
- public TestTailMap(AbstractTestMap main) {
+ final K fromKey;
+ final K invalidKey;
+
+ public TestTailMap(AbstractTestMap<K, V> main) {
super("SortedMap.TailMap", main);
- SortedMap sm = (SortedMap) main.makeFullMap();
- for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map<K, V> sm = main.makeFullMap();
+ for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue());
}
@@ -245,18 +262,18 @@
this.subSortedValues.subList(0, this.subSortedValues.size() - SUBSIZE).clear();
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(0, SUBSIZE));
}
- public Map makeEmptyMap() {
+ public SortedMap<K, V> makeObject() {
// done this way so toKey is correctly set in the returned map
- return ((SortedMap) main.makeEmptyMap()).tailMap(fromKey);
+ return ((SortedMap<K, V>) main.makeObject()).tailMap(fromKey);
}
- public Map makeFullMap() {
- return ((SortedMap) main.makeFullMap()).tailMap(fromKey);
+ public SortedMap<K, V> makeFullMap() {
+ return ((SortedMap<K, V>) main.makeFullMap()).tailMap(fromKey);
}
public void testTailMapOutOfRange() {
if (isPutAddSupported() == false) return;
resetEmpty();
try {
- ((SortedMap) map).put(invalidKey, subSortedValues.get(0));
+ getMap().put(invalidKey, subSortedValues.get(0));
fail();
} catch (IllegalArgumentException ex) {}
verify();
@@ -276,45 +293,45 @@
// "D:/dev/collections/data/test/FixedSizeSortedMap.fullCollection.version3.1.TailMapView.obj");
// }
}
-
- public static class TestSubMap extends TestViewMap {
+
+ public static class TestSubMap<K, V> extends TestViewMap<K, V> {
static final int SUBSIZE = 3;
- final Object fromKey;
- final Object toKey;
-
- public TestSubMap(AbstractTestMap main) {
+ final K fromKey;
+ final K toKey;
+
+ public TestSubMap(AbstractTestMap<K, V> main) {
super("SortedMap.SubMap", main);
- SortedMap sm = (SortedMap) main.makeFullMap();
- for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map<K, V> sm = main.makeFullMap();
+ for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue());
}
this.fromKey = this.subSortedKeys.get(SUBSIZE);
this.toKey = this.subSortedKeys.get(this.subSortedKeys.size() - SUBSIZE);
-
+
this.subSortedKeys.subList(0, SUBSIZE).clear();
this.subSortedKeys.subList(this.subSortedKeys.size() - SUBSIZE, this.subSortedKeys.size()).clear();
-
+
this.subSortedValues.subList(0, SUBSIZE).clear();
this.subSortedValues.subList(this.subSortedValues.size() - SUBSIZE, this.subSortedValues.size()).clear();
-
+
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(
SUBSIZE, this.main.getNewSampleValues().length - SUBSIZE));
}
-
- public Map makeEmptyMap() {
+
+ public SortedMap<K, V> makeObject() {
// done this way so toKey is correctly set in the returned map
- return ((SortedMap) main.makeEmptyMap()).subMap(fromKey, toKey);
+ return ((SortedMap<K, V>) main.makeObject()).subMap(fromKey, toKey);
}
- public Map makeFullMap() {
- return ((SortedMap) main.makeFullMap()).subMap(fromKey, toKey);
+ public SortedMap<K, V> makeFullMap() {
+ return ((SortedMap<K, V>) main.makeFullMap()).subMap(fromKey, toKey);
}
public void testSubMapOutOfRange() {
if (isPutAddSupported() == false) return;
resetEmpty();
try {
- ((SortedMap) map).put(toKey, subSortedValues.get(0));
+ getMap().put(toKey, subSortedValues.get(0));
fail();
} catch (IllegalArgumentException ex) {}
verify();
@@ -334,5 +351,20 @@
// "D:/dev/collections/data/test/TransformedSortedMap.fullCollection.version3.1.SubMapView.obj");
// }
}
-
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SortedMap<K, V> getMap() {
+ return (SortedMap<K, V>) super.getMap();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SortedMap<K, V> getConfirmed() {
+ return (SortedMap<K, V>) super.getConfirmed();
+ }
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java Tue Sep 15 05:29:56 2009
@@ -33,7 +33,7 @@
*
* @author Commons-Collections team
*/
-public class TestCaseInsensitiveMap extends AbstractTestIterableMap {
+public class TestCaseInsensitiveMap<K, V> extends AbstractTestIterableMap<K, V> {
public TestCaseInsensitiveMap(String testName) {
super(testName);
@@ -42,74 +42,77 @@
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestCaseInsensitiveMap.class);
}
- public Map makeEmptyMap() {
- return new CaseInsensitiveMap();
+ public CaseInsensitiveMap<K, V> makeObject() {
+ return new CaseInsensitiveMap<K, V>();
}
-
+
public String getCompatibilityVersion() {
return "3";
}
-
+
//-------------------------------------------------------------------------
-
+
+ @SuppressWarnings("unchecked")
public void testCaseInsensitive() {
- Map map = new CaseInsensitiveMap();
- map.put("One", "One");
- map.put("Two", "Two");
- assertEquals("One", (String) map.get("one"));
- assertEquals("One", (String) map.get("oNe"));
- map.put("two", "Three");
- assertEquals("Three", (String) map.get("Two"));
- }
-
+ Map<K, V> map = makeObject();
+ map.put((K) "One", (V) "One");
+ map.put((K) "Two", (V) "Two");
+ assertEquals("One", map.get("one"));
+ assertEquals("One", map.get("oNe"));
+ map.put((K) "two", (V) "Three");
+ assertEquals("Three", map.get("Two"));
+ }
+
+ @SuppressWarnings("unchecked")
public void testNullHandling() {
- Map map = new CaseInsensitiveMap();
- map.put("One", "One");
- map.put("Two", "Two");
- map.put(null, "Three");
- assertEquals("Three", (String) map.get(null));
- map.put(null, "Four");
- assertEquals("Four", (String) map.get(null));
- Set keys = map.keySet();
+ Map<K, V> map = makeObject();
+ map.put((K) "One", (V) "One");
+ map.put((K) "Two", (V) "Two");
+ map.put(null, (V) "Three");
+ assertEquals("Three", map.get(null));
+ map.put(null, (V) "Four");
+ assertEquals("Four", map.get(null));
+ Set<K> keys = map.keySet();
assertTrue(keys.contains("one"));
assertTrue(keys.contains("two"));
assertTrue(keys.contains(null));
assertEquals(3, keys.size());
}
-
+
public void testPutAll() {
- Map map = new HashMap();
+ Map<Object, String> map = new HashMap<Object, String>();
map.put("One", "One");
map.put("Two", "Two");
map.put("one", "Three");
map.put(null, "Four");
map.put(new Integer(20), "Five");
- Map caseInsensitiveMap = new CaseInsensitiveMap(map);
+ Map<Object, String> caseInsensitiveMap = new CaseInsensitiveMap<Object, String>(map);
assertEquals(4, caseInsensitiveMap.size()); // ones collapsed
- Set keys = caseInsensitiveMap.keySet();
+ Set<Object> keys = caseInsensitiveMap.keySet();
assertTrue(keys.contains("one"));
assertTrue(keys.contains("two"));
assertTrue(keys.contains(null));
assertTrue(keys.contains(Integer.toString(20)));
assertEquals(4, keys.size());
- assertTrue(!caseInsensitiveMap.containsValue("One")
+ assertTrue(!caseInsensitiveMap.containsValue("One")
|| !caseInsensitiveMap.containsValue("Three")); // ones collaped
assertEquals("Four", caseInsensitiveMap.get(null));
- }
+ }
+ @SuppressWarnings("unchecked")
public void testClone() {
- CaseInsensitiveMap map = new CaseInsensitiveMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ CaseInsensitiveMap<K, V> map = new CaseInsensitiveMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ CaseInsensitiveMap<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
-
+
/*
public void testCreate() throws Exception {
resetEmpty();
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java Tue Sep 15 05:29:56 2009
@@ -16,7 +16,6 @@
*/
package org.apache.commons.collections.map;
-import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -33,7 +32,7 @@
*
* @author Stephen Colebourne
*/
-public class TestFixedSizeSortedMap extends AbstractTestSortedMap {
+public class TestFixedSizeSortedMap<K, V> extends AbstractTestSortedMap<K, V> {
public TestFixedSizeSortedMap(String testName) {
super(testName);
@@ -49,16 +48,16 @@
}
//-----------------------------------------------------------------------
- public Map makeEmptyMap() {
- return FixedSizeSortedMap.decorate(new TreeMap());
+ public SortedMap<K, V> makeObject() {
+ return FixedSizeSortedMap.decorate(new TreeMap<K, V>());
}
- public Map makeFullMap() {
- SortedMap map = new TreeMap();
+ public SortedMap<K, V> makeFullMap() {
+ SortedMap<K, V> map = new TreeMap<K, V>();
addSampleMappings(map);
return FixedSizeSortedMap.decorate(map);
}
-
+
public boolean isSubMapViewsSerializable() {
// TreeMap sub map views have a bug in deserialization.
return false;
@@ -76,7 +75,7 @@
public String getCompatibilityVersion() {
return "3.1";
}
-
+
// public void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk(
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFlat3Map.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFlat3Map.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFlat3Map.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestFlat3Map.java Tue Sep 15 05:29:56 2009
@@ -27,6 +27,7 @@
import junit.textui.TestRunner;
import org.apache.commons.collections.BulkTest;
+import org.apache.commons.collections.IterableMap;
import org.apache.commons.collections.MapIterator;
import org.apache.commons.collections.iterators.AbstractTestMapIterator;
@@ -37,7 +38,7 @@
*
* @author Stephen Colebourne
*/
-public class TestFlat3Map extends AbstractTestIterableMap {
+public class TestFlat3Map<K, V> extends AbstractTestIterableMap<K, V> {
private static final Integer ONE = new Integer(1);
private static final Integer TWO = new Integer(2);
@@ -45,7 +46,7 @@
private static final String TEN = "10";
private static final String TWENTY = "20";
private static final String THIRTY = "30";
-
+
public TestFlat3Map(String testName) {
super(testName);
}
@@ -53,75 +54,80 @@
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestFlat3Map.class);
}
- public Map makeEmptyMap() {
- return new Flat3Map();
+ public Flat3Map<K, V> makeObject() {
+ return new Flat3Map<K, V>();
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testEquals1() {
- Flat3Map map1 = new Flat3Map();
- map1.put("a", "testA");
- map1.put("b", "testB");
- Flat3Map map2 = new Flat3Map();
- map2.put("a", "testB");
- map2.put("b", "testA");
+ Flat3Map<K, V> map1 = makeObject();
+ map1.put((K) "a", (V) "testA");
+ map1.put((K) "b", (V) "testB");
+ Flat3Map<K, V> map2 = makeObject();
+ map2.put((K) "a", (V) "testB");
+ map2.put((K) "b", (V) "testA");
assertEquals(false, map1.equals(map2));
}
+ @SuppressWarnings("unchecked")
public void testEquals2() {
- Flat3Map map1 = new Flat3Map();
- map1.put("a", "testA");
- map1.put("b", "testB");
- Flat3Map map2 = new Flat3Map();
- map2.put("a", "testB");
- map2.put("c", "testA");
+ Flat3Map<K, V> map1 = makeObject();
+ map1.put((K) "a", (V) "testA");
+ map1.put((K) "b", (V) "testB");
+ Flat3Map<K, V> map2 = makeObject();
+ map2.put((K) "a", (V) "testB");
+ map2.put((K) "c", (V) "testA");
assertEquals(false, map1.equals(map2));
}
+ @SuppressWarnings("unchecked")
public void testClone2() {
- Flat3Map map = new Flat3Map();
+ Flat3Map<K, V> map = makeObject();
assertEquals(0, map.size());
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
assertEquals(2, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
assertSame(TEN, map.get(ONE));
assertSame(TWENTY, map.get(TWO));
- // clone works (size = 2)
- Flat3Map cloned = (Flat3Map) map.clone();
+ // clone works (size = 2)
+ Flat3Map<K, V> cloned = map.clone();
assertEquals(2, cloned.size());
assertEquals(true, cloned.containsKey(ONE));
assertEquals(true, cloned.containsKey(TWO));
assertSame(TEN, cloned.get(ONE));
assertSame(TWENTY, cloned.get(TWO));
-
+
// change original doesn't change clone
- map.put(TEN, ONE);
- map.put(TWENTY, TWO);
+ map.put((K) TEN, (V) ONE);
+ map.put((K) TWENTY, (V) TWO);
assertEquals(4, map.size());
assertEquals(2, cloned.size());
assertEquals(true, cloned.containsKey(ONE));
assertEquals(true, cloned.containsKey(TWO));
assertSame(TEN, cloned.get(ONE));
assertSame(TWENTY, cloned.get(TWO));
- }
+ }
+
+ @SuppressWarnings("unchecked")
public void testClone4() {
- Flat3Map map = new Flat3Map();
+ Flat3Map<K, V> map = makeObject();
assertEquals(0, map.size());
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(TEN, ONE);
- map.put(TWENTY, TWO);
-
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) TEN, (V) ONE);
+ map.put((K) TWENTY, (V) TWO);
+
// clone works (size = 4)
- Flat3Map cloned = (Flat3Map) map.clone();
+ Flat3Map<K, V> cloned = map.clone();
assertEquals(4, map.size());
assertEquals(4, cloned.size());
assertEquals(true, cloned.containsKey(ONE));
@@ -132,7 +138,7 @@
assertSame(TWENTY, cloned.get(TWO));
assertSame(ONE, cloned.get(TEN));
assertSame(TWO, cloned.get(TWENTY));
-
+
// change original doesn't change clone
map.clear();
assertEquals(0, map.size());
@@ -146,9 +152,10 @@
assertSame(ONE, cloned.get(TEN));
assertSame(TWO, cloned.get(TWENTY));
}
-
+
+ @SuppressWarnings("unchecked")
public void testSerialisation0() throws Exception {
- Flat3Map map = new Flat3Map();
+ Flat3Map<K, V> map = makeObject();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(map);
@@ -161,12 +168,13 @@
assertEquals(0, map.size());
assertEquals(0, ser.size());
}
-
+
+ @SuppressWarnings("unchecked")
public void testSerialisation2() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
-
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(map);
@@ -183,14 +191,15 @@
assertEquals(TEN, ser.get(ONE));
assertEquals(TWENTY, ser.get(TWO));
}
-
+
+ @SuppressWarnings("unchecked")
public void testSerialisation4() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(TEN, ONE);
- map.put(TWENTY, TWO);
-
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) TEN, (V) ONE);
+ map.put((K) TWENTY, (V) TWO);
+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(map);
@@ -213,15 +222,16 @@
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testEntryIteratorSetValue1() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- Iterator it = map.entrySet().iterator();
- Map.Entry entry = (Map.Entry) it.next();
- entry.setValue("NewValue");
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
+ Map.Entry<K, V> entry = it.next();
+ entry.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -231,16 +241,17 @@
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testEntryIteratorSetValue2() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- Iterator it = map.entrySet().iterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
it.next();
- Map.Entry entry = (Map.Entry) it.next();
- entry.setValue("NewValue");
+ Map.Entry<K, V> entry = it.next();
+ entry.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -250,17 +261,18 @@
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testEntryIteratorSetValue3() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- Iterator it = map.entrySet().iterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
it.next();
it.next();
- Map.Entry entry = (Map.Entry) it.next();
- entry.setValue("NewValue");
+ Map.Entry<K, V> entry = it.next();
+ entry.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -271,15 +283,16 @@
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testMapIteratorSetValue1() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- MapIterator it = map.mapIterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ MapIterator<K, V> it = map.mapIterator();
it.next();
- it.setValue("NewValue");
+ it.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -289,16 +302,17 @@
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testMapIteratorSetValue2() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- MapIterator it = map.mapIterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ MapIterator<K, V> it = map.mapIterator();
it.next();
it.next();
- it.setValue("NewValue");
+ it.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -308,17 +322,18 @@
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testMapIteratorSetValue3() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- MapIterator it = map.mapIterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ MapIterator<K, V> it = map.mapIterator();
it.next();
it.next();
it.next();
- it.setValue("NewValue");
+ it.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -332,16 +347,16 @@
public BulkTest bulkTestMapIterator() {
return new TestFlatMapIterator();
}
-
- public class TestFlatMapIterator extends AbstractTestMapIterator {
+
+ public class TestFlatMapIterator extends AbstractTestMapIterator<K, V> {
public TestFlatMapIterator() {
super("TestFlatMapIterator");
}
-
- public Object[] addSetValues() {
+
+ public V[] addSetValues() {
return TestFlat3Map.this.getNewSampleValues();
}
-
+
public boolean supportsRemove() {
return TestFlat3Map.this.isRemoveSupported();
}
@@ -350,32 +365,32 @@
return TestFlat3Map.this.isSetValueSupported();
}
- public MapIterator makeEmptyMapIterator() {
+ public MapIterator<K, V> makeEmptyIterator() {
resetEmpty();
- return ((Flat3Map) TestFlat3Map.this.map).mapIterator();
+ return TestFlat3Map.this.getMap().mapIterator();
}
- public MapIterator makeFullMapIterator() {
+ public MapIterator<K, V> makeObject() {
resetFull();
- return ((Flat3Map) TestFlat3Map.this.map).mapIterator();
+ return TestFlat3Map.this.getMap().mapIterator();
}
-
- public Map getMap() {
+
+ public IterableMap<K, V> getMap() {
// assumes makeFullMapIterator() called first
- return TestFlat3Map.this.map;
+ return TestFlat3Map.this.getMap();
}
-
- public Map getConfirmedMap() {
+
+ public Map<K, V> getConfirmedMap() {
// assumes makeFullMapIterator() called first
- return TestFlat3Map.this.confirmed;
+ return TestFlat3Map.this.getConfirmed();
}
-
+
public void verify() {
super.verify();
TestFlat3Map.this.verify();
}
}
-
+
public String getCompatibilityVersion() {
return "3.1";
}
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestHashedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestHashedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestHashedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestHashedMap.java Tue Sep 15 05:29:56 2009
@@ -16,8 +16,6 @@
*/
package org.apache.commons.collections.map;
-import java.util.Map;
-
import junit.framework.Test;
import junit.textui.TestRunner;
@@ -30,7 +28,7 @@
*
* @author Stephen Colebourne
*/
-public class TestHashedMap extends AbstractTestIterableMap {
+public class TestHashedMap<K, V> extends AbstractTestIterableMap<K, V> {
public TestHashedMap(String testName) {
super(testName);
@@ -39,29 +37,30 @@
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestHashedMap.class);
}
- public Map makeEmptyMap() {
- return new HashedMap();
+ public HashedMap<K, V> makeObject() {
+ return new HashedMap<K, V>();
}
-
+
public String getCompatibilityVersion() {
return "3";
}
+ @SuppressWarnings("unchecked")
public void testClone() {
- HashedMap map = new HashedMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ HashedMap<K, V> map = new HashedMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ HashedMap<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
public void testInternalState() {
- HashedMap map = new HashedMap(42, 0.75f);
+ HashedMap<K, V> map = new HashedMap<K, V>(42, 0.75f);
assertEquals(0.75f, map.loadFactor, 0.1f);
assertEquals(0, map.size);
assertEquals(64, map.data.length);
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestIdentityMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestIdentityMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestIdentityMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestIdentityMap.java Tue Sep 15 05:29:56 2009
@@ -35,8 +35,8 @@
*
* @author Stephen Colebourne
*/
-public class TestIdentityMap extends AbstractTestObject {
-
+public class TestIdentityMap<K, V> extends AbstractTestObject {
+
private static final Integer I1A = new Integer(1);
private static final Integer I1B = new Integer(1);
private static final Integer I2A = new Integer(2);
@@ -49,26 +49,27 @@
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return new TestSuite(TestIdentityMap.class);
// return BulkTest.makeSuite(TestIdentityMap.class); // causes race condition!
}
-
- public Object makeObject() {
- return new IdentityMap();
+
+ public IdentityMap<K, V> makeObject() {
+ return new IdentityMap<K, V>();
}
-
+
public String getCompatibilityVersion() {
return "3";
}
-
+
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testBasics() {
- IterableMap map = new IdentityMap();
+ IterableMap<K, V> map = new IdentityMap<K, V>();
assertEquals(0, map.size());
-
- map.put(I1A, I2A);
+
+ map.put((K) I1A, (V) I2A);
assertEquals(1, map.size());
assertSame(I2A, map.get(I1A));
assertSame(null, map.get(I1B));
@@ -76,8 +77,8 @@
assertEquals(false, map.containsKey(I1B));
assertEquals(true, map.containsValue(I2A));
assertEquals(false, map.containsValue(I2B));
-
- map.put(I1A, I2B);
+
+ map.put((K) I1A, (V) I2B);
assertEquals(1, map.size());
assertSame(I2B, map.get(I1A));
assertSame(null, map.get(I1B));
@@ -85,8 +86,8 @@
assertEquals(false, map.containsKey(I1B));
assertEquals(false, map.containsValue(I2A));
assertEquals(true, map.containsValue(I2B));
-
- map.put(I1B, I2B);
+
+ map.put((K) I1B, (V) I2B);
assertEquals(2, map.size());
assertSame(I2B, map.get(I1A));
assertSame(I2B, map.get(I1B));
@@ -95,45 +96,48 @@
assertEquals(false, map.containsValue(I2A));
assertEquals(true, map.containsValue(I2B));
}
-
+
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testHashEntry() {
- IterableMap map = new IdentityMap();
-
- map.put(I1A, I2A);
- map.put(I1B, I2A);
-
- Map.Entry entry1 = (Map.Entry) map.entrySet().iterator().next();
- Iterator it = map.entrySet().iterator();
- Map.Entry entry2 = (Map.Entry) it.next();
- Map.Entry entry3 = (Map.Entry) it.next();
-
+ IterableMap<K, V> map = new IdentityMap<K, V>();
+
+ map.put((K) I1A, (V) I2A);
+ map.put((K) I1B, (V) I2A);
+
+ Map.Entry<K, V> entry1 = map.entrySet().iterator().next();
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
+ Map.Entry<K, V> entry2 = it.next();
+ Map.Entry<K, V> entry3 = it.next();
+
assertEquals(true, entry1.equals(entry2));
assertEquals(true, entry2.equals(entry1));
assertEquals(false, entry1.equals(entry3));
}
-
+
/**
* Compare the current serialized form of the Map
* against the canonical version in SVN.
*/
+ @SuppressWarnings("unchecked")
public void testEmptyMapCompatibility() throws IOException, ClassNotFoundException {
// test to make sure the canonical form has been preserved
- Map map = (Map) makeObject();
+ Map<K, V> map = makeObject();
if (map instanceof Serializable && !skipSerializedCanonicalTests()) {
Map map2 = (Map) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map));
assertEquals("Map is empty", 0, map2.size());
}
}
+ @SuppressWarnings("unchecked")
public void testClone() {
- IdentityMap map = new IdentityMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ IdentityMap<K, V> map = new IdentityMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ Map<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
-
+
// public void testCreate() throws Exception {
// Map map = new IdentityMap();
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/IdentityMap.emptyCollection.version3.obj");