http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/TestFactoryUtils.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/TestFactoryUtils.java b/src/test/org/apache/commons/collections/TestFactoryUtils.java index 3abbeaa..257acef 100644 --- a/src/test/org/apache/commons/collections/TestFactoryUtils.java +++ b/src/test/org/apache/commons/collections/TestFactoryUtils.java @@ -80,7 +80,7 @@ public class TestFactoryUtils extends junit.framework.TestCase { //------------------------------------------------------------------ public void testNullFactory() { - Factory factory = FactoryUtils.nullFactory(); + Factory<Object> factory = FactoryUtils.nullFactory(); assertNotNull(factory); Object created = factory.create(); assertNull(created); @@ -90,7 +90,7 @@ public class TestFactoryUtils extends junit.framework.TestCase { //------------------------------------------------------------------ public void testConstantFactoryNull() { - Factory factory = FactoryUtils.constantFactory(null); + Factory<Object> factory = FactoryUtils.constantFactory(null); assertNotNull(factory); Object created = factory.create(); assertNull(created); @@ -98,9 +98,9 @@ public class TestFactoryUtils extends junit.framework.TestCase { public void testConstantFactoryConstant() { Integer constant = new Integer(9); - Factory factory = FactoryUtils.constantFactory(constant); + Factory<Integer> factory = FactoryUtils.constantFactory(constant); assertNotNull(factory); - Object created = factory.create(); + Integer created = factory.create(); assertSame(constant, created); } @@ -113,9 +113,9 @@ public class TestFactoryUtils extends junit.framework.TestCase { public void testPrototypeFactoryPublicCloneMethod() throws Exception { Date proto = new Date(); - Factory factory = FactoryUtils.prototypeFactory(proto); + Factory<Date> factory = FactoryUtils.prototypeFactory(proto); assertNotNull(factory); - Object created = factory.create(); + Date created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); @@ -125,13 +125,13 @@ public class TestFactoryUtils extends junit.framework.TestCase { out.writeObject(factory); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); - Object dest = in.readObject(); + in.readObject(); in.close(); } public void testPrototypeFactoryPublicCopyConstructor() throws Exception { Mock1 proto = new Mock1(6); - Factory factory = FactoryUtils.prototypeFactory(proto); + Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto); assertNotNull(factory); Object created = factory.create(); assertTrue(proto != created); @@ -145,21 +145,21 @@ public class TestFactoryUtils extends junit.framework.TestCase { } catch (NotSerializableException ex) { out.close(); } - factory = FactoryUtils.prototypeFactory(new Mock2("S")); + factory = FactoryUtils.<Object>prototypeFactory(new Mock2("S")); buffer = new ByteArrayOutputStream(); out = new ObjectOutputStream(buffer); out.writeObject(factory); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); - Object dest = in.readObject(); + in.readObject(); in.close(); } public void testPrototypeFactoryPublicSerialization() throws Exception { Integer proto = new Integer(9); - Factory factory = FactoryUtils.prototypeFactory(proto); + Factory<Integer> factory = FactoryUtils.prototypeFactory(proto); assertNotNull(factory); - Object created = factory.create(); + Integer created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); @@ -169,17 +169,16 @@ public class TestFactoryUtils extends junit.framework.TestCase { out.writeObject(factory); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); - Object dest = in.readObject(); + in.readObject(); in.close(); } public void testPrototypeFactoryPublicSerializationError() { Mock2 proto = new Mock2(new Object()); - Factory factory = FactoryUtils.prototypeFactory(proto); + Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto); assertNotNull(factory); try { - Object created = factory.create(); - + factory.create(); } catch (FunctorException ex) { assertTrue(ex.getCause() instanceof IOException); return; @@ -190,8 +189,7 @@ public class TestFactoryUtils extends junit.framework.TestCase { public void testPrototypeFactoryPublicBad() { Object proto = new Object(); try { - Factory factory = FactoryUtils.prototypeFactory(proto); - + FactoryUtils.prototypeFactory(proto); } catch (IllegalArgumentException ex) { return; } @@ -216,6 +214,7 @@ public class TestFactoryUtils extends junit.framework.TestCase { } } + @SuppressWarnings("serial") public static class Mock2 implements Serializable { private final Object iVal; public Mock2(Object val) {
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/TestIteratorUtils.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/TestIteratorUtils.java b/src/test/org/apache/commons/collections/TestIteratorUtils.java index 03afc1d..b729306 100644 --- a/src/test/org/apache/commons/collections/TestIteratorUtils.java +++ b/src/test/org/apache/commons/collections/TestIteratorUtils.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,9 +33,9 @@ import org.apache.commons.collections.iterators.EmptyOrderedMapIterator; /** * Tests for IteratorUtils. - * + * * @version $Revision$ $Date$ - * + * * @author Unknown */ public class TestIteratorUtils extends BulkTest { @@ -53,16 +53,16 @@ public class TestIteratorUtils extends BulkTest { } public void testToList() { - List list = new ArrayList(); + List<Object> list = new ArrayList<Object>(); list.add(new Integer(1)); list.add("Two"); list.add(null); - List result = IteratorUtils.toList(list.iterator()); + List<Object> result = IteratorUtils.toList(list.iterator()); assertEquals(list, result); } public void testToArray() { - List list = new ArrayList(); + List<Object> list = new ArrayList<Object>(); list.add(new Integer(1)); list.add("Two"); list.add(null); @@ -71,137 +71,137 @@ public class TestIteratorUtils extends BulkTest { } public void testToArray2() { - List list = new ArrayList(); + List<String> list = new ArrayList<String>(); list.add("One"); list.add("Two"); list.add(null); String[] result = (String[]) IteratorUtils.toArray(list.iterator(), String.class); assertEquals(list, Arrays.asList(result)); } - + public void testArrayIterator() { Object[] objArray = {"a", "b", "c"}; - ResettableIterator iterator = IteratorUtils.arrayIterator(objArray); + ResettableIterator<Object> iterator = IteratorUtils.arrayIterator(objArray); assertTrue(iterator.next().equals("a")); assertTrue(iterator.next().equals("b")); iterator.reset(); assertTrue(iterator.next().equals("a")); - + try { iterator = IteratorUtils.arrayIterator(new Integer(0)); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } - + try { iterator = IteratorUtils.arrayIterator(null); fail("Expecting NullPointerException"); } catch (NullPointerException ex) { // expected } - + iterator = IteratorUtils.arrayIterator(objArray, 1); assertTrue(iterator.next().equals("b")); - + try { iterator = IteratorUtils.arrayIterator(objArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayIterator(objArray, 3); assertTrue(!iterator.hasNext()); iterator.reset(); - + try { iterator = IteratorUtils.arrayIterator(objArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayIterator(objArray, 2, 3); assertTrue(iterator.next().equals("c")); - + try { iterator = IteratorUtils.arrayIterator(objArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayIterator(objArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayIterator(objArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } - + int[] intArray = {0, 1, 2}; iterator = IteratorUtils.arrayIterator(intArray); assertTrue(iterator.next().equals(new Integer(0))); assertTrue(iterator.next().equals(new Integer(1))); iterator.reset(); assertTrue(iterator.next().equals(new Integer(0))); - + iterator = IteratorUtils.arrayIterator(intArray, 1); assertTrue(iterator.next().equals(new Integer(1))); - + try { iterator = IteratorUtils.arrayIterator(intArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayIterator(intArray, 3); assertTrue(!iterator.hasNext()); iterator.reset(); - + try { iterator = IteratorUtils.arrayIterator(intArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayIterator(intArray, 2, 3); assertTrue(iterator.next().equals(new Integer(2))); - + try { iterator = IteratorUtils.arrayIterator(intArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayIterator(intArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayIterator(intArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected - } + } } - + public void testArrayListIterator() { Object[] objArray = {"a", "b", "c", "d"}; - ResettableListIterator iterator = IteratorUtils.arrayListIterator(objArray); + ResettableListIterator<Object> iterator = IteratorUtils.arrayListIterator(objArray); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.nextIndex() == 0); @@ -215,158 +215,158 @@ public class TestIteratorUtils extends BulkTest { assertTrue(iterator.next().equals("d")); assertTrue(iterator.nextIndex() == 4); // size of list assertTrue(iterator.previousIndex() == 3); - + try { iterator = IteratorUtils.arrayListIterator(new Integer(0)); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } - + try { iterator = IteratorUtils.arrayListIterator(null); fail("Expecting NullPointerException"); } catch (NullPointerException ex) { // expected } - + iterator = IteratorUtils.arrayListIterator(objArray, 1); - assertTrue(iterator.previousIndex() == -1); + assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); - assertTrue(iterator.nextIndex() == 0); + assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals("b")); - assertTrue(iterator.previousIndex() == 0); - + assertTrue(iterator.previousIndex() == 0); + try { iterator = IteratorUtils.arrayListIterator(objArray, -1); fail("Expecting IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayListIterator(objArray, 3); assertTrue(iterator.hasNext()); try { - Object x = iterator.previous(); + iterator.previous(); fail("Expecting NoSuchElementException."); } catch (NoSuchElementException ex) { // expected } - + try { iterator = IteratorUtils.arrayListIterator(objArray, 5); fail("Expecting IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayListIterator(objArray, 2, 3); assertTrue(iterator.next().equals("c")); - + try { iterator = IteratorUtils.arrayListIterator(objArray, 2, 5); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayListIterator(objArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayListIterator(objArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } - + int[] intArray = {0, 1, 2}; iterator = IteratorUtils.arrayListIterator(intArray); - assertTrue(iterator.previousIndex() == -1); + assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); - assertTrue(iterator.nextIndex() == 0); + assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals(new Integer(0))); - assertTrue(iterator.previousIndex() == 0); - assertTrue(iterator.nextIndex() == 1); + assertTrue(iterator.previousIndex() == 0); + assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals(new Integer(1))); - assertTrue(iterator.previousIndex() == 1); - assertTrue(iterator.nextIndex() == 2); + assertTrue(iterator.previousIndex() == 1); + assertTrue(iterator.nextIndex() == 2); assertTrue(iterator.previous().equals(new Integer(1))); assertTrue(iterator.next().equals(new Integer(1))); - + iterator = IteratorUtils.arrayListIterator(intArray, 1); - assertTrue(iterator.previousIndex() == -1); + assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); - assertTrue(iterator.nextIndex() == 0); + assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals(new Integer(1))); assertTrue(iterator.previous().equals(new Integer(1))); assertTrue(iterator.next().equals(new Integer(1))); - assertTrue(iterator.previousIndex() == 0); - assertTrue(iterator.nextIndex() == 1); + assertTrue(iterator.previousIndex() == 0); + assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals(new Integer(2))); - assertTrue(iterator.previousIndex() == 1); - assertTrue(iterator.nextIndex() == 2); + assertTrue(iterator.previousIndex() == 1); + assertTrue(iterator.nextIndex() == 2); assertTrue(iterator.previous().equals(new Integer(2))); - assertTrue(iterator.previousIndex() == 0); - assertTrue(iterator.nextIndex() == 1); - + assertTrue(iterator.previousIndex() == 0); + assertTrue(iterator.nextIndex() == 1); + try { iterator = IteratorUtils.arrayListIterator(intArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayListIterator(intArray, 3); assertTrue(!iterator.hasNext()); - + try { iterator = IteratorUtils.arrayListIterator(intArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + iterator = IteratorUtils.arrayListIterator(intArray, 2, 3); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.next().equals(new Integer(2))); assertTrue(iterator.hasPrevious()); assertTrue(!iterator.hasNext()); - - + + try { iterator = IteratorUtils.arrayListIterator(intArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayListIterator(intArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { // expected } - + try { iterator = IteratorUtils.arrayListIterator(intArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected - } + } } - + /** * Gets an immutable Iterator operating on the elements ["a", "b", "c", "d"]. */ - private Iterator getImmutableIterator() { - List list = new ArrayList(); + private Iterator<String> getImmutableIterator() { + List<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); @@ -377,8 +377,8 @@ public class TestIteratorUtils extends BulkTest { /** * Gets an immutable ListIterator operating on the elements ["a", "b", "c", "d"]. */ - private ListIterator getImmutableListIterator() { - List list = new ArrayList(); + private ListIterator<String> getImmutableListIterator() { + List<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); @@ -411,7 +411,7 @@ public class TestIteratorUtils extends BulkTest { fail(); } catch (IllegalStateException ex) {} } - + //----------------------------------------------------------------------- /** * Test empty list iterator @@ -451,11 +451,12 @@ public class TestIteratorUtils extends BulkTest { fail(); } catch (UnsupportedOperationException ex) {} } - + //----------------------------------------------------------------------- /** * Test empty map iterator */ + @SuppressWarnings("unchecked") public void testEmptyMapIterator() { assertSame(EmptyMapIterator.INSTANCE, IteratorUtils.EMPTY_MAP_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_MAP_ITERATOR instanceof Iterator); @@ -465,7 +466,7 @@ public class TestIteratorUtils extends BulkTest { assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR instanceof OrderedIterator); assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR instanceof OrderedMapIterator); assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR.hasNext()); - ((ResettableIterator) IteratorUtils.EMPTY_MAP_ITERATOR).reset(); + ((ResettableIterator<Object>) IteratorUtils.EMPTY_MAP_ITERATOR).reset(); assertSame(IteratorUtils.EMPTY_MAP_ITERATOR, IteratorUtils.EMPTY_MAP_ITERATOR); assertSame(IteratorUtils.EMPTY_MAP_ITERATOR, IteratorUtils.emptyMapIterator()); try { @@ -489,11 +490,12 @@ public class TestIteratorUtils extends BulkTest { fail(); } catch (IllegalStateException ex) {} } - + //----------------------------------------------------------------------- /** * Test empty map iterator */ + @SuppressWarnings("unchecked") public void testEmptyOrderedIterator() { assertSame(EmptyOrderedIterator.INSTANCE, IteratorUtils.EMPTY_ORDERED_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof Iterator); @@ -503,7 +505,7 @@ public class TestIteratorUtils extends BulkTest { assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof MapIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR.hasNext()); assertEquals(false, IteratorUtils.EMPTY_ORDERED_ITERATOR.hasPrevious()); - ((ResettableIterator) IteratorUtils.EMPTY_ORDERED_ITERATOR).reset(); + ((ResettableIterator<Object>) IteratorUtils.EMPTY_ORDERED_ITERATOR).reset(); assertSame(IteratorUtils.EMPTY_ORDERED_ITERATOR, IteratorUtils.EMPTY_ORDERED_ITERATOR); assertSame(IteratorUtils.EMPTY_ORDERED_ITERATOR, IteratorUtils.emptyOrderedIterator()); try { @@ -519,11 +521,12 @@ public class TestIteratorUtils extends BulkTest { fail(); } catch (IllegalStateException ex) {} } - + //----------------------------------------------------------------------- /** * Test empty map iterator */ + @SuppressWarnings("unchecked") public void testEmptyOrderedMapIterator() { assertSame(EmptyOrderedMapIterator.INSTANCE, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof Iterator); @@ -533,7 +536,7 @@ public class TestIteratorUtils extends BulkTest { assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof ListIterator); assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.hasNext()); assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.hasPrevious()); - ((ResettableIterator) IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR).reset(); + ((ResettableIterator<Object>) IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR).reset(); assertSame(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR); assertSame(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR, IteratorUtils.emptyOrderedMapIterator()); try { @@ -561,13 +564,13 @@ public class TestIteratorUtils extends BulkTest { fail(); } catch (IllegalStateException ex) {} } - + //----------------------------------------------------------------------- /** * Test next() and hasNext() for an immutable Iterator. */ public void testUnmodifiableIteratorIteration() { - Iterator iterator = getImmutableIterator(); + Iterator<String> iterator = getImmutableIterator(); assertTrue(iterator.hasNext()); @@ -593,7 +596,7 @@ public class TestIteratorUtils extends BulkTest { * ListIterator. */ public void testUnmodifiableListIteratorIteration() { - ListIterator listIterator = getImmutableListIterator(); + ListIterator<String> listIterator = getImmutableListIterator(); assertTrue(!listIterator.hasPrevious()); assertTrue(listIterator.hasNext()); @@ -643,7 +646,7 @@ public class TestIteratorUtils extends BulkTest { * Test remove() for an immutable Iterator. */ public void testUnmodifiableIteratorImmutability() { - Iterator iterator = getImmutableIterator(); + Iterator<String> iterator = getImmutableIterator(); try { iterator.remove(); @@ -669,7 +672,7 @@ public class TestIteratorUtils extends BulkTest { * Test remove() for an immutable ListIterator. */ public void testUnmodifiableListIteratorImmutability() { - ListIterator listIterator = getImmutableListIterator(); + ListIterator<String> listIterator = getImmutableListIterator(); try { listIterator.remove(); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/TestLinkedList.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/TestLinkedList.java b/src/test/org/apache/commons/collections/TestLinkedList.java index e2ce122..62e7166 100644 --- a/src/test/org/apache/commons/collections/TestLinkedList.java +++ b/src/test/org/apache/commons/collections/TestLinkedList.java @@ -38,46 +38,21 @@ import org.apache.commons.collections.list.AbstractTestList; * * @author Rich Dougherty */ -public abstract class TestLinkedList extends AbstractTestList { +public abstract class TestLinkedList<T> extends AbstractTestList<T> { public TestLinkedList(String testName) { super(testName); } - public List makeEmptyList() { - return makeEmptyLinkedList(); - } - - public List makeFullList() { - return makeFullLinkedList(); - } - - /** - * Return a new, empty {@link LinkedList} to be used for testing. - * - * @return an empty list for testing. - */ - protected abstract LinkedList makeEmptyLinkedList(); - - /** - * Return a new, full {@link List} to be used for testing. - * - * @return a full list for testing - */ - protected LinkedList makeFullLinkedList() { - // only works if list supports optional "addAll(Collection)" - LinkedList list = makeEmptyLinkedList(); - list.addAll(Arrays.asList(getFullElements())); - return list; - } + public abstract LinkedList<T> makeObject(); /** * Returns the {@link #collection} field cast to a {@link LinkedList}. * * @return the collection field as a List */ - protected LinkedList getLinkedList() { - return (LinkedList)collection; + public LinkedList<T> getCollection() { + return (LinkedList<T>) super.getCollection(); } /** @@ -85,24 +60,25 @@ public abstract class TestLinkedList extends AbstractTestList { * * @return the confirmed field as a List */ - protected LinkedList getConfirmedLinkedList() { - return (LinkedList)confirmed; + protected LinkedList<T> getConfirmedLinkedList() { + return (LinkedList<T>) getConfirmed(); } /** * Tests {@link LinkedList#addFirst(Object)}. */ + @SuppressWarnings("unchecked") public void testLinkedListAddFirst() { if (!isAddSupported()) return; - Object o = "hello"; + T o = (T) "hello"; resetEmpty(); - getLinkedList().addFirst(o); + getCollection().addFirst(o); getConfirmedLinkedList().addFirst(o); verify(); resetFull(); - getLinkedList().addFirst(o); + getCollection().addFirst(o); getConfirmedLinkedList().addFirst(o); verify(); } @@ -110,17 +86,18 @@ public abstract class TestLinkedList extends AbstractTestList { /** * Tests {@link LinkedList#addLast(Object)}. */ + @SuppressWarnings("unchecked") public void testLinkedListAddLast() { if (!isAddSupported()) return; - Object o = "hello"; + T o = (T) "hello"; resetEmpty(); - getLinkedList().addLast(o); + getCollection().addLast(o); getConfirmedLinkedList().addLast(o); verify(); resetFull(); - getLinkedList().addLast(o); + getCollection().addLast(o); getConfirmedLinkedList().addLast(o); verify(); } @@ -131,7 +108,7 @@ public abstract class TestLinkedList extends AbstractTestList { public void testLinkedListGetFirst() { resetEmpty(); try { - getLinkedList().getFirst(); + getCollection().getFirst(); fail("getFirst() should throw a NoSuchElementException for an " + "empty list."); } catch (NoSuchElementException e) { @@ -140,7 +117,7 @@ public abstract class TestLinkedList extends AbstractTestList { verify(); resetFull(); - Object first = getLinkedList().getFirst(); + Object first = getCollection().getFirst(); Object confirmedFirst = getConfirmedLinkedList().getFirst(); assertEquals("Result returned by getFirst() was wrong.", confirmedFirst, first); @@ -153,7 +130,7 @@ public abstract class TestLinkedList extends AbstractTestList { public void testLinkedListGetLast() { resetEmpty(); try { - getLinkedList().getLast(); + getCollection().getLast(); fail("getLast() should throw a NoSuchElementException for an " + "empty list."); } catch (NoSuchElementException e) { @@ -162,7 +139,7 @@ public abstract class TestLinkedList extends AbstractTestList { verify(); resetFull(); - Object last = getLinkedList().getLast(); + Object last = getCollection().getLast(); Object confirmedLast = getConfirmedLinkedList().getLast(); assertEquals("Result returned by getLast() was wrong.", confirmedLast, last); @@ -177,7 +154,7 @@ public abstract class TestLinkedList extends AbstractTestList { resetEmpty(); try { - getLinkedList().removeFirst(); + getCollection().removeFirst(); fail("removeFirst() should throw a NoSuchElementException for " + "an empty list."); } catch (NoSuchElementException e) { @@ -186,7 +163,7 @@ public abstract class TestLinkedList extends AbstractTestList { verify(); resetFull(); - Object first = getLinkedList().removeFirst(); + Object first = getCollection().removeFirst(); Object confirmedFirst = getConfirmedLinkedList().removeFirst(); assertEquals("Result returned by removeFirst() was wrong.", confirmedFirst, first); @@ -201,7 +178,7 @@ public abstract class TestLinkedList extends AbstractTestList { resetEmpty(); try { - getLinkedList().removeLast(); + getCollection().removeLast(); fail("removeLast() should throw a NoSuchElementException for " + "an empty list."); } catch (NoSuchElementException e) { @@ -210,7 +187,7 @@ public abstract class TestLinkedList extends AbstractTestList { verify(); resetFull(); - Object last = getLinkedList().removeLast(); + Object last = getCollection().removeLast(); Object confirmedLast = getConfirmedLinkedList().removeLast(); assertEquals("Result returned by removeLast() was wrong.", confirmedLast, last); @@ -220,15 +197,15 @@ public abstract class TestLinkedList extends AbstractTestList { /** * Returns an empty {@link ArrayList}. */ - public Collection makeConfirmedCollection() { - return new LinkedList(); + public Collection<T> makeConfirmedCollection() { + return new LinkedList<T>(); } /** * Returns a full {@link ArrayList}. */ - public Collection makeConfirmedFullCollection() { - List list = new LinkedList(); + public Collection<T> makeConfirmedFullCollection() { + List<T> list = new LinkedList<T>(); list.addAll(Arrays.asList(getFullElements())); return list; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/TestListUtils.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/TestListUtils.java b/src/test/org/apache/commons/collections/TestListUtils.java index c30d843..69bc0cf 100644 --- a/src/test/org/apache/commons/collections/TestListUtils.java +++ b/src/test/org/apache/commons/collections/TestListUtils.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,9 +28,9 @@ import org.apache.commons.collections.list.PredicatedList; /** * Tests for ListUtils. - * + * * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne * @author Neil O'Toole * @author Matthew Hawthorne @@ -46,7 +46,7 @@ public class TestListUtils extends BulkTest { private String[] fullArray; private List<String> fullList; - + public TestListUtils(String name) { super(name); } @@ -57,10 +57,9 @@ public class TestListUtils extends BulkTest { public void setUp() { fullArray = new String[]{a, b, c, d, e}; - fullList = new ArrayList(Arrays.asList(fullArray)); + fullList = new ArrayList<String>(Arrays.asList(fullArray)); } - - + public void testNothing() { } @@ -68,7 +67,7 @@ public class TestListUtils extends BulkTest { * Tests intersecting a non-empty list with an empty list. */ public void testIntersectNonEmptyWithEmptyList() { - final List<?> empty = Collections.EMPTY_LIST; + final List<String> empty = Collections.<String>emptyList(); assertTrue("result not empty", ListUtils.intersection(empty, fullList).isEmpty()); } @@ -85,7 +84,7 @@ public class TestListUtils extends BulkTest { */ public void testIntersectNonEmptySubset() { // create a copy - final List<String> other = new ArrayList(fullList); + final List<String> other = new ArrayList<String>(fullList); // remove a few items assertNotNull(other.remove(0)); @@ -111,25 +110,21 @@ public class TestListUtils extends BulkTest { } public void testPredicatedList() { - Predicate predicate = new Predicate() { + Predicate<Object> predicate = new Predicate<Object>() { public boolean evaluate(Object o) { return o instanceof String; } }; - List list = - ListUtils.predicatedList(new ArrayStack(), predicate); - assertTrue("returned object should be a PredicatedList", - list instanceof PredicatedList); + List<Object> list = ListUtils.predicatedList(new ArrayStack<Object>(), predicate); + assertTrue("returned object should be a PredicatedList", list instanceof PredicatedList); try { - list = - ListUtils.predicatedList(new ArrayStack(), null); + list = ListUtils.predicatedList(new ArrayStack<Object>(), null); fail("Expecting IllegalArgumentException for null predicate."); } catch (IllegalArgumentException ex) { // expected } try { - list = - ListUtils.predicatedList(null, predicate); + list = ListUtils.predicatedList(null, predicate); fail("Expecting IllegalArgumentException for null list."); } catch (IllegalArgumentException ex) { // expected @@ -137,29 +132,29 @@ public class TestListUtils extends BulkTest { } public void testLazyList() { - List list = ListUtils.lazyList(new ArrayList(), new Factory() { + List<Integer> list = ListUtils.lazyList(new ArrayList<Integer>(), new Factory<Integer>() { private int index; - public Object create() { + public Integer create() { index++; return new Integer(index); } }); - assertNotNull((Integer)list.get(5)); + assertNotNull(list.get(5)); assertEquals(6, list.size()); - assertNotNull((Integer)list.get(5)); + assertNotNull(list.get(5)); assertEquals(6, list.size()); } public void testEquals() { - Collection data = Arrays.asList( new String[] { "a", "b", "c" }); - - List a = new ArrayList( data ); - List b = new ArrayList( data ); - + Collection<String> data = Arrays.asList( new String[] { "a", "b", "c" }); + + List<String> a = new ArrayList<String>( data ); + List<String> b = new ArrayList<String>( data ); + assertEquals(true, a.equals(b)); assertEquals(true, ListUtils.isEqualList(a, b)); a.clear(); @@ -168,13 +163,13 @@ public class TestListUtils extends BulkTest { assertEquals(false, ListUtils.isEqualList(null, b)); assertEquals(true, ListUtils.isEqualList(null, null)); } - + public void testHashCode() { - Collection data = Arrays.asList( new String[] { "a", "b", "c" }); - - List a = new ArrayList( data ); - List b = new ArrayList( data ); - + Collection<String> data = Arrays.asList( new String[] { "a", "b", "c" }); + + List<String> a = new ArrayList<String>(data); + List<String> b = new ArrayList<String>(data); + assertEquals(true, a.hashCode() == b.hashCode()); assertEquals(true, a.hashCode() == ListUtils.hashCodeForList(a)); assertEquals(true, b.hashCode() == ListUtils.hashCodeForList(b)); @@ -183,20 +178,20 @@ public class TestListUtils extends BulkTest { assertEquals(false, ListUtils.hashCodeForList(a) == ListUtils.hashCodeForList(b)); assertEquals(0, ListUtils.hashCodeForList(null)); } - + public void testRetainAll() { - List sub = new ArrayList(); + List<String> sub = new ArrayList<String>(); sub.add(a); sub.add(b); sub.add(x); - List retained = ListUtils.retainAll(fullList, sub); + List<String> retained = ListUtils.retainAll(fullList, sub); assertTrue(retained.size() == 2); sub.remove(x); assertTrue(retained.equals(sub)); fullList.retainAll(sub); assertTrue(retained.equals(fullList)); - + try { ListUtils.retainAll(null, null); fail("expecting NullPointerException"); @@ -204,20 +199,20 @@ public class TestListUtils extends BulkTest { } public void testRemoveAll() { - List sub = new ArrayList(); + List<String> sub = new ArrayList<String>(); sub.add(a); sub.add(b); sub.add(x); - List remainder = ListUtils.removeAll(fullList, sub); + List<String> remainder = ListUtils.removeAll(fullList, sub); assertTrue(remainder.size() == 3); fullList.removeAll(sub); assertTrue(remainder.equals(fullList)); - + try { ListUtils.removeAll(null, null); fail("expecting NullPointerException"); } catch(NullPointerException npe) {} // this is what we want } - + } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/TestMapUtils.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/TestMapUtils.java b/src/test/org/apache/commons/collections/TestMapUtils.java index e1243d7..2f7006c 100644 --- a/src/test/org/apache/commons/collections/TestMapUtils.java +++ b/src/test/org/apache/commons/collections/TestMapUtils.java @@ -51,13 +51,12 @@ public class TestMapUtils extends BulkTest { super(name); } - public static Test suite() { return BulkTest.makeSuite(TestMapUtils.class); } - public Predicate getPredicate() { - return new Predicate() { + public Predicate<Object> getPredicate() { + return new Predicate<Object>() { public boolean evaluate(Object o) { return o instanceof String; } @@ -65,10 +64,9 @@ public class TestMapUtils extends BulkTest { } public void testPredicatedMap() { - Predicate p = getPredicate(); - Map map = MapUtils.predicatedMap(new HashMap(), p, p); - assertTrue("returned object should be a PredicatedMap", - map instanceof PredicatedMap); + Predicate<Object> p = getPredicate(); + Map<Object, Object> map = MapUtils.predicatedMap(new HashMap<Object, Object>(), p, p); + assertTrue("returned object should be a PredicatedMap", map instanceof PredicatedMap); try { map = MapUtils.predicatedMap(null, p, p); fail("Expecting IllegalArgumentException for null map."); @@ -78,32 +76,32 @@ public class TestMapUtils extends BulkTest { } public void testLazyMapFactory() { - Factory factory = FactoryUtils.constantFactory(new Integer(5)); - Map map = MapUtils.lazyMap(new HashMap(), factory); + Factory<Integer> factory = FactoryUtils.constantFactory(new Integer(5)); + Map<Object, Object> map = MapUtils.lazyMap(new HashMap<Object, Object>(), factory); assertTrue(map instanceof LazyMap); try { - map = MapUtils.lazyMap(new HashMap(), (Factory) null); + map = MapUtils.lazyMap(new HashMap<Object, Object>(), (Factory<Object>) null); fail("Expecting IllegalArgumentException for null factory"); } catch (IllegalArgumentException e) { // expected } try { - map = MapUtils.lazyMap(null, factory); + map = MapUtils.lazyMap((Map<Object, Object>) null, factory); fail("Expecting IllegalArgumentException for null map"); } catch (IllegalArgumentException e) { // expected } - Transformer transformer = TransformerUtils.asTransformer(factory); - map = MapUtils.lazyMap(new HashMap(), transformer); + Transformer<Object, Integer> transformer = TransformerUtils.asTransformer(factory); + map = MapUtils.lazyMap(new HashMap<Object, Object>(), transformer); assertTrue(map instanceof LazyMap); try { - map = MapUtils.lazyMap(new HashMap(), (Transformer) null); + map = MapUtils.lazyMap(new HashMap<Object, Object>(), (Transformer<Object, Object>) null); fail("Expecting IllegalArgumentException for null transformer"); } catch (IllegalArgumentException e) { // expected } try { - map = MapUtils.lazyMap(null, transformer); + map = MapUtils.lazyMap((Map<Object, Object>) null, transformer); fail("Expecting IllegalArgumentException for null map"); } catch (IllegalArgumentException e) { // expected @@ -111,7 +109,7 @@ public class TestMapUtils extends BulkTest { } public void testLazyMapTransformer() { - Map map = MapUtils.lazyMap(new HashMap(), new Transformer() { + Map<Object, Object> map = MapUtils.lazyMap(new HashMap<Object, Object>(), new Transformer<Object, Object>() { public Object transform(Object mapKey) { if (mapKey instanceof String) { return new Integer((String) mapKey); @@ -131,20 +129,20 @@ public class TestMapUtils extends BulkTest { } public void testInvertMap() { - final Map in = new HashMap( 5 , 1 ); - in.put( "1" , "A" ); - in.put( "2" , "B" ); - in.put( "3" , "C" ); - in.put( "4" , "D" ); - in.put( "5" , "E" ); + final Map<String, String> in = new HashMap<String, String>(5, 1); + in.put("1", "A"); + in.put("2", "B"); + in.put("3", "C"); + in.put("4", "D"); + in.put("5", "E"); - final Set inKeySet = new HashSet( in.keySet() ); - final Set inValSet = new HashSet( in.values() ); + final Set<String> inKeySet = new HashSet<String>(in.keySet()); + final Set<String> inValSet = new HashSet<String>(in.values()); - final Map out = MapUtils.invertMap(in); + final Map<String, String> out = MapUtils.invertMap(in); - final Set outKeySet = new HashSet( out.keySet() ); - final Set outValSet = new HashSet( out.values() ); + final Set<String> outKeySet = new HashSet<String>(out.keySet()); + final Set<String> outValSet = new HashSet<String>(out.values()); assertTrue( inKeySet.equals( outValSet )); assertTrue( inValSet.equals( outKeySet )); @@ -166,11 +164,11 @@ public class TestMapUtils extends BulkTest { fail(); } catch (NullPointerException ex) {} - Map test = MapUtils.putAll(new HashMap(), new String[0]); + Map<String, String> test = MapUtils.putAll(new HashMap<String, String>(), new String[0]); assertEquals(0, test.size()); // sub array - test = MapUtils.putAll(new HashMap(), new String[][] { + test = MapUtils.putAll(new HashMap<String, String>(), new String[][] { {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} @@ -184,7 +182,7 @@ public class TestMapUtils extends BulkTest { assertEquals(3, test.size()); try { - MapUtils.putAll(new HashMap(), new String[][] { + MapUtils.putAll(new HashMap<String, String>(), new String[][] { {"RED", "#FF0000"}, null, {"BLUE", "#0000FF"} @@ -193,7 +191,7 @@ public class TestMapUtils extends BulkTest { } catch (IllegalArgumentException ex) {} try { - MapUtils.putAll(new HashMap(), new String[][] { + MapUtils.putAll(new HashMap<String, String>(), new String[][] { {"RED", "#FF0000"}, {"GREEN"}, {"BLUE", "#0000FF"} @@ -202,7 +200,7 @@ public class TestMapUtils extends BulkTest { } catch (IllegalArgumentException ex) {} try { - MapUtils.putAll(new HashMap(), new String[][] { + MapUtils.putAll(new HashMap<String, String>(), new String[][] { {"RED", "#FF0000"}, {}, {"BLUE", "#0000FF"} @@ -211,7 +209,7 @@ public class TestMapUtils extends BulkTest { } catch (IllegalArgumentException ex) {} // flat array - test = MapUtils.putAll(new HashMap(), new String[] { + test = MapUtils.putAll(new HashMap<String, String>(), new String[] { "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF" @@ -224,7 +222,7 @@ public class TestMapUtils extends BulkTest { assertEquals("#0000FF", test.get("BLUE")); assertEquals(3, test.size()); - test = MapUtils.putAll(new HashMap(), new String[] { + test = MapUtils.putAll(new HashMap<String, String>(), new String[] { "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF", @@ -239,10 +237,10 @@ public class TestMapUtils extends BulkTest { assertEquals(3, test.size()); // map entry - test = MapUtils.putAll(new HashMap(), new Object[] { - new DefaultMapEntry("RED", "#FF0000"), - new DefaultMapEntry("GREEN", "#00FF00"), - new DefaultMapEntry("BLUE", "#0000FF") + test = MapUtils.putAll(new HashMap<String, String>(), new Object[] { + new DefaultMapEntry<String, String>("RED", "#FF0000"), + new DefaultMapEntry<String, String>("GREEN", "#00FF00"), + new DefaultMapEntry<String, String>("BLUE", "#0000FF") }); assertEquals(true, test.containsKey("RED")); assertEquals("#FF0000", test.get("RED")); @@ -253,10 +251,10 @@ public class TestMapUtils extends BulkTest { assertEquals(3, test.size()); // key value - test = MapUtils.putAll(new HashMap(), new Object[] { - new DefaultKeyValue("RED", "#FF0000"), - new DefaultKeyValue("GREEN", "#00FF00"), - new DefaultKeyValue("BLUE", "#0000FF") + test = MapUtils.putAll(new HashMap<String, String>(), new Object[] { + new DefaultKeyValue<String, String>("RED", "#FF0000"), + new DefaultKeyValue<String, String>("GREEN", "#00FF00"), + new DefaultKeyValue<String, String>("BLUE", "#0000FF") }); assertEquals(true, test.containsKey("RED")); assertEquals("#FF0000", test.get("RED")); @@ -268,17 +266,17 @@ public class TestMapUtils extends BulkTest { } public void testConvertResourceBundle() { - final Map in = new HashMap( 5 , 1 ); - in.put( "1" , "A" ); - in.put( "2" , "B" ); - in.put( "3" , "C" ); - in.put( "4" , "D" ); - in.put( "5" , "E" ); + final Map<String, String> in = new HashMap<String, String>( 5 , 1 ); + in.put("1", "A"); + in.put("2", "B"); + in.put("3", "C"); + in.put("4", "D"); + in.put("5", "E"); ResourceBundle b = new ListResourceBundle() { public Object[][] getContents() { final Object[][] contents = new Object[ in.size() ][2]; - final Iterator i = in.keySet().iterator(); + final Iterator<String> i = in.keySet().iterator(); int n = 0; while ( i.hasNext() ) { final Object key = i.next(); @@ -291,20 +289,19 @@ public class TestMapUtils extends BulkTest { } }; - final Map out = MapUtils.toMap(b); + final Map<String, Object> out = MapUtils.toMap(b); assertTrue( in.equals(out)); } public void testDebugAndVerbosePrintCasting() { - final Map inner = new HashMap(2, 1); - inner.put( new Integer(2) , "B" ); - inner.put( new Integer(3) , "C" ); - - final Map outer = new HashMap(2, 1); - outer.put( new Integer(0) , inner ); - outer.put( new Integer(1) , "A"); + final Map<Integer, String> inner = new HashMap<Integer, String>(2, 1); + inner.put(2, "B"); + inner.put(3, "C"); + final Map<Integer, Object> outer = new HashMap<Integer, Object>(2, 1); + outer.put(0, inner); + outer.put(1, "A"); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); @@ -341,10 +338,10 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new TreeMap(); // treeMap guarantees order across JDKs for test - map.put( new Integer(2) , "B" ); - map.put( new Integer(3) , "C" ); - map.put( new Integer(4) , null ); + final Map<Integer, String> map = new TreeMap<Integer, String>(); // treeMap guarantees order across JDKs for test + map.put(2, "B"); + map.put(3, "C"); + map.put(4, null); outPrint.println("{"); outPrint.println(INDENT + "2 = B"); @@ -364,10 +361,10 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new TreeMap(); // treeMap guarantees order across JDKs for test - map.put( new Integer(2) , "B" ); - map.put( new Integer(3) , "C" ); - map.put( new Integer(4) , null ); + final Map<Integer, String> map = new TreeMap<Integer, String>(); // treeMap guarantees order across JDKs for test + map.put(2, "B"); + map.put(3, "C"); + map.put(4, null); outPrint.println("{"); outPrint.println(INDENT + "2 = B " + String.class.getName()); @@ -407,7 +404,7 @@ public class TestMapUtils extends BulkTest { public void testVerbosePrintNullStream() { try { - MapUtils.verbosePrint(null, "Map", new HashMap()); + MapUtils.verbosePrint(null, "Map", new HashMap<Object, Object>()); fail("Should generate NullPointerException"); } catch (NullPointerException expected) { } @@ -415,7 +412,7 @@ public class TestMapUtils extends BulkTest { public void testDebugPrintNullStream() { try { - MapUtils.debugPrint(null, "Map", new HashMap()); + MapUtils.debugPrint(null, "Map", new HashMap<Object, Object>()); fail("Should generate NullPointerException"); } catch (NullPointerException expected) { } @@ -427,8 +424,8 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new HashMap(); - map.put( null , "A" ); + final Map<Object, String> map = new HashMap<Object, String>(); + map.put(null, "A"); outPrint.println("{"); outPrint.println(INDENT + "null = A " + String.class.getName()); @@ -446,8 +443,8 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new HashMap(); - map.put( null , "A" ); + final Map<Object, String> map = new HashMap<Object, String>(); + map.put(null, "A"); outPrint.println("{"); outPrint.println(INDENT + "null = A"); @@ -465,8 +462,8 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new HashMap(); - map.put( null , map ); + final Map<Object, Map<?, ?>> map = new HashMap<Object, Map<?, ?>>(); + map.put(null, map); outPrint.println("{"); outPrint.println(INDENT + "null = (this Map) " + HashMap.class.getName()); @@ -484,8 +481,8 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new HashMap(); - map.put( null , map ); + final Map<Object, Map<?, ?>> map = new HashMap<Object, Map<?, ?>>(); + map.put(null, map); outPrint.println("{"); outPrint.println(INDENT + "null = (this Map)"); @@ -503,10 +500,10 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new HashMap(); - final Map map2= new HashMap(); - map.put( null , map2 ); - map2.put( "2", "B" ); + final Map<Object, Object> map = new HashMap<Object, Object>(); + final Map<Object, Object> map2= new HashMap<Object, Object>(); + map.put(null, map2); + map2.put("2", "B"); outPrint.println("{"); outPrint.println(INDENT + "null = "); @@ -527,10 +524,10 @@ public class TestMapUtils extends BulkTest { final String INDENT = " "; - final Map map = new HashMap(); - final Map map2= new HashMap(); - map.put( null , map2 ); - map2.put( "2", "B" ); + final Map<Object, Object> map = new HashMap<Object, Object>(); + final Map<Object, Object> map2= new HashMap<Object, Object>(); + map.put(null, map2); + map2.put("2", "B"); outPrint.println("{"); outPrint.println(INDENT + "null = "); @@ -567,14 +564,14 @@ public class TestMapUtils extends BulkTest { out.reset(); - final Map inner = new TreeMap(); // treeMap guarantees order across JDKs for test - inner.put( new Integer(2) , "B" ); - inner.put( new Integer(3) , "C" ); + final Map<Integer, String> inner = new TreeMap<Integer, String>(); // treeMap guarantees order across JDKs for test + inner.put(2, "B"); + inner.put(3, "C"); - final Map outer = new TreeMap(); - outer.put( new Integer(1) , inner ); - outer.put( new Integer(0) , "A"); - outer.put( new Integer(7) , outer); + final Map<Integer, Object> outer = new TreeMap<Integer, Object>(); + outer.put(1, inner); + outer.put(0, "A"); + outer.put(7, outer); MapUtils.verbosePrint(outPrint, "Print Map", outer); assertEquals(EXPECTED_OUT, out.toString()); @@ -602,14 +599,14 @@ public class TestMapUtils extends BulkTest { out.reset(); - final Map inner = new TreeMap(); // treeMap guarantees order across JDKs for test - inner.put( new Integer(2) , "B" ); - inner.put( new Integer(3) , "C" ); + final Map<Integer, String> inner = new TreeMap<Integer, String>(); // treeMap guarantees order across JDKs for test + inner.put(2, "B"); + inner.put(3, "C"); - final Map outer = new TreeMap(); - outer.put( new Integer(1) , inner ); - outer.put( new Integer(0) , "A"); - outer.put( new Integer(7) , outer); + final Map<Integer, Object> outer = new TreeMap<Integer, Object>(); + outer.put(1, inner); + outer.put(0, "A"); + outer.put(7, outer); MapUtils.debugPrint(outPrint, "Print Map", outer); assertEquals(EXPECTED_OUT, out.toString()); @@ -622,21 +619,20 @@ public class TestMapUtils extends BulkTest { final String LABEL = "Print Map"; final String INDENT = " "; + final Map<Integer, Object> grandfather = new TreeMap<Integer, Object>();// treeMap guarantees order across JDKs for test + final Map<Integer, Object> father = new TreeMap<Integer, Object>(); + final Map<Integer, Object> son = new TreeMap<Integer, Object>(); - final Map grandfather = new TreeMap();// treeMap guarantees order across JDKs for test - final Map father = new TreeMap(); - final Map son = new TreeMap(); + grandfather.put(0, "A"); + grandfather.put(1, father); - grandfather.put( new Integer(0), "A" ); - grandfather.put( new Integer(1), father ); + father.put(2, "B"); + father.put(3, grandfather); + father.put(4, son); - father.put( new Integer(2), "B" ); - father.put( new Integer(3), grandfather); - father.put( new Integer(4), son); - - son.put( new Integer(5), "C"); - son.put( new Integer(6), grandfather); - son.put( new Integer(7), father); + son.put(5, "C"); + son.put(6, grandfather); + son.put(7, father); outPrint.println(LABEL + " = "); outPrint.println("{"); @@ -669,21 +665,20 @@ public class TestMapUtils extends BulkTest { final String LABEL = "Print Map"; final String INDENT = " "; + final Map<Integer, Object> grandfather = new TreeMap<Integer, Object>();// treeMap guarantees order across JDKs for test + final Map<Integer, Object> father = new TreeMap<Integer, Object>(); + final Map<Integer, Object> son = new TreeMap<Integer, Object>(); - final Map grandfather = new TreeMap();// treeMap guarantees order across JDKs for test - final Map father = new TreeMap(); - final Map son = new TreeMap(); - - grandfather.put( new Integer(0), "A" ); - grandfather.put( new Integer(1), father ); + grandfather.put(0, "A"); + grandfather.put(1, father); - father.put( new Integer(2), "B" ); - father.put( new Integer(3), grandfather); - father.put( new Integer(4), son); + father.put(2, "B"); + father.put(3, grandfather); + father.put(4, son); - son.put( new Integer(5), "C"); - son.put( new Integer(6), grandfather); - son.put( new Integer(7), father); + son.put(5, "C"); + son.put(6, grandfather); + son.put(7, father); outPrint.println(LABEL + " = "); outPrint.println("{"); @@ -711,34 +706,34 @@ public class TestMapUtils extends BulkTest { //----------------------------------------------------------------------- public void testIsEmptyWithEmptyMap() { - Map map = new HashMap(); + Map<Object, Object> map = new HashMap<Object, Object>(); assertEquals(true, MapUtils.isEmpty(map)); } public void testIsEmptyWithNonEmptyMap() { - Map map = new HashMap(); + Map<String, String> map = new HashMap<String, String>(); map.put("item", "value"); assertEquals(false, MapUtils.isEmpty(map)); } public void testIsEmptyWithNull() { - Map map = null; + Map<Object, Object> map = null; assertEquals(true, MapUtils.isEmpty(map)); } public void testIsNotEmptyWithEmptyMap() { - Map map = new HashMap(); + Map<Object, Object> map = new HashMap<Object, Object>(); assertEquals(false, MapUtils.isNotEmpty(map)); } public void testIsNotEmptyWithNonEmptyMap() { - Map map = new HashMap(); + Map<String, String> map = new HashMap<String, String>(); map.put("item", "value"); assertEquals(true, MapUtils.isNotEmpty(map)); } public void testIsNotEmptyWithNull() { - Map map = null; + Map<Object, Object> map = null; assertEquals(false, MapUtils.isNotEmpty(map)); }
