http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java b/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java index b59367f..1fa8164 100644 --- a/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java +++ b/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.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. @@ -27,57 +27,54 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.Predicate; -import org.apache.commons.collections.PredicateUtils; +import org.apache.commons.collections.functors.TruePredicate; /** - * Extension of {@link TestPredicatedMap} for exercising the + * Extension of {@link TestPredicatedMap} for exercising the * {@link PredicatedSortedMap} implementation. * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Phil Steitz */ -public class TestPredicatedSortedMap extends AbstractTestSortedMap{ - - protected static final Predicate truePredicate = PredicateUtils.truePredicate(); - protected static final Predicate testPredicate = new Predicate() { +public class TestPredicatedSortedMap<K, V> extends AbstractTestSortedMap<K, V> { + + protected static final Predicate<Object> truePredicate = TruePredicate.truePredicate(); + + protected static final Predicate<Object> testPredicate = new Predicate<Object>() { public boolean evaluate(Object o) { return (o instanceof String); } }; - + public TestPredicatedSortedMap(String testName) { super(testName); } - + public static Test suite() { return new TestSuite(TestPredicatedSortedMap.class); } - + public static void main(String args[]) { String[] testCaseName = { TestPredicatedSortedMap.class.getName()}; junit.textui.TestRunner.main(testCaseName); } //----------------------------------------------------------------------- - protected SortedMap decorateMap(SortedMap map, Predicate keyPredicate, - Predicate valuePredicate) { + protected SortedMap<K, V> decorateMap(SortedMap<K, V> map, Predicate<? super K> keyPredicate, + Predicate<? super V> valuePredicate) { return PredicatedSortedMap.decorate(map, keyPredicate, valuePredicate); } - - public Map makeEmptyMap() { - return decorateMap(new TreeMap(), truePredicate, truePredicate); + + public SortedMap<K, V> makeObject() { + return decorateMap(new TreeMap<K, V>(), truePredicate, truePredicate); } - - public Map makeTestMap() { - return decorateMap(new TreeMap(), testPredicate, testPredicate); - } - - public SortedMap makeTestSortedMap() { - return decorateMap(new TreeMap(), testPredicate, testPredicate); + + public SortedMap<K, V> makeTestMap() { + return decorateMap(new TreeMap<K, V>(), testPredicate, testPredicate); } - + public boolean isSubMapViewsSerializable() { // TreeMap sub map views have a bug in deserialization. return false; @@ -89,28 +86,30 @@ public class TestPredicatedSortedMap extends AbstractTestSortedMap{ // from TestPredicatedMap //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testEntrySet() { - SortedMap map = makeTestSortedMap(); + SortedMap<K, V> map = makeTestMap(); assertTrue("returned entryset should not be null", map.entrySet() != null); - map = decorateMap(new TreeMap(), null, null); - map.put("oneKey", "oneValue"); + map = decorateMap(new TreeMap<K, V>(), null, null); + map.put((K) "oneKey", (V) "oneValue"); assertTrue("returned entryset should contain one entry", - map.entrySet().size() == 1); + map.entrySet().size() == 1); map = decorateMap(map, null, null); } - + + @SuppressWarnings("unchecked") public void testPut() { - Map map = makeTestMap(); + Map<K, V> map = makeTestMap(); try { - map.put("Hi", new Integer(3)); + map.put((K) "Hi", (V) new Integer(3)); fail("Illegal value should raise IllegalArgument"); } catch (IllegalArgumentException e) { // expected } try { - map.put(new Integer(3), "Hi"); + map.put((K) new Integer(3), (V) "Hi"); fail("Illegal key should raise IllegalArgument"); } catch (IllegalArgumentException e) { // expected @@ -119,11 +118,11 @@ public class TestPredicatedSortedMap extends AbstractTestSortedMap{ assertTrue(!map.containsKey(new Integer(3))); assertTrue(!map.containsValue(new Integer(3))); - Map map2 = new HashMap(); - map2.put("A", "a"); - map2.put("B", "b"); - map2.put("C", "c"); - map2.put("c", new Integer(3)); + Map<K, V> map2 = new HashMap<K, V>(); + map2.put((K) "A", (V) "a"); + map2.put((K) "B", (V) "b"); + map2.put((K) "C", (V) "c"); + map2.put((K) "c", (V) new Integer(3)); try { map.putAll(map2); @@ -132,52 +131,53 @@ public class TestPredicatedSortedMap extends AbstractTestSortedMap{ // expected } - map.put("E", "e"); - Iterator iterator = map.entrySet().iterator(); + map.put((K) "E", (V) "e"); + Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator(); try { - Map.Entry entry = (Map.Entry)iterator.next(); - entry.setValue(new Integer(3)); + Map.Entry<K, V> entry = iterator.next(); + entry.setValue((V) new Integer(3)); fail("Illegal value should raise IllegalArgument"); } catch (IllegalArgumentException e) { // expected } - - map.put("F", "f"); + + map.put((K) "F", (V) "f"); iterator = map.entrySet().iterator(); - Map.Entry entry = (Map.Entry)iterator.next(); - entry.setValue("x"); - + Map.Entry<K, V> entry = iterator.next(); + entry.setValue((V) "x"); + } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testSortOrder() { - SortedMap map = makeTestSortedMap(); - map.put("A", "a"); - map.put("B", "b"); + SortedMap<K, V> map = makeTestMap(); + map.put((K) "A", (V) "a"); + map.put((K) "B", (V) "b"); try { - map.put(null, "c"); + map.put(null, (V) "c"); fail("Null key should raise IllegalArgument"); } catch (IllegalArgumentException e) { // expected } - map.put("C", "c"); + map.put((K) "C", (V) "c"); try { - map.put("D", null); + map.put((K) "D", null); fail("Null value should raise IllegalArgument"); } catch (IllegalArgumentException e) { // expected } assertEquals("First key should be A", map.firstKey(), "A"); assertEquals("Last key should be C", map.lastKey(), "C"); - assertEquals("First key in tail map should be B", - map.tailMap("B").firstKey(), "B"); - assertEquals("Last key in head map should be B", - map.headMap("C").lastKey(), "B"); + assertEquals("First key in tail map should be B", + map.tailMap((K) "B").firstKey(), "B"); + assertEquals("Last key in head map should be B", + map.headMap((K) "C").lastKey(), "B"); assertEquals("Last key in submap should be B", - map.subMap("A","C").lastKey(), "B"); - - Comparator c = map.comparator(); - assertTrue("natural order, so comparator should be null", + map.subMap((K) "A",(K) "C").lastKey(), "B"); + + Comparator<? super K> c = map.comparator(); + assertTrue("natural order, so comparator should be null", c == null); }
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java b/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java index 6bb4432..421950a 100644 --- a/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java +++ b/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.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. @@ -24,17 +24,18 @@ import junit.framework.Test; import org.apache.commons.collections.BulkTest; import org.apache.commons.collections.IterableMap; +import org.apache.commons.collections.map.AbstractReferenceMap.ReferenceStrength; /** - * Tests for ReferenceIdentityMap. - * + * Tests for ReferenceIdentityMap. + * * @version $Revision$ * * @author Paul Jack * @author Stephen Colebourne * @author Guilhem Lavaux */ -public class TestReferenceIdentityMap extends AbstractTestIterableMap { +public class TestReferenceIdentityMap<K, V> extends AbstractTestIterableMap<K, V> { private static final Integer I1A = new Integer(1); private static final Integer I1B = new Integer(1); @@ -54,15 +55,15 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { junit.textui.TestRunner.main(testCaseName); } - public Map makeEmptyMap() { - ReferenceIdentityMap map = new ReferenceIdentityMap(ReferenceIdentityMap.WEAK, ReferenceIdentityMap.WEAK); - return map; + public ReferenceIdentityMap<K, V> makeObject() { + return new ReferenceIdentityMap<K, V>(ReferenceStrength.WEAK, ReferenceStrength.WEAK); } - - public Map makeConfirmedMap() { + + public Map<K, V> makeConfirmedMap() { // Testing against another [collections] class generally isn't a good idea, - // but the alternative is a JDK1.4 dependency in the tests - return new IdentityMap(); + // but the closest alternative is IdentityHashMap, which propagates reference-equality down to keySet and values. + // arguably ReferenceIdentityMap should do the same but that's a later discussion. + return new IdentityMap<K, V>(); } public boolean isAllowNullKey() { @@ -78,11 +79,12 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testBasics() { - IterableMap map = new ReferenceIdentityMap(ReferenceIdentityMap.HARD, ReferenceIdentityMap.HARD); + IterableMap<K, V> map = new ReferenceIdentityMap<K, V>(ReferenceStrength.HARD, ReferenceStrength.HARD); 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)); @@ -90,8 +92,8 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { 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)); @@ -99,8 +101,8 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { 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)); @@ -109,45 +111,46 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { assertEquals(false, map.containsValue(I2A)); assertEquals(true, map.containsValue(I2B)); } - + //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testHashEntry() { - IterableMap map = new ReferenceIdentityMap(ReferenceIdentityMap.HARD, ReferenceIdentityMap.HARD); - - 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 ReferenceIdentityMap<K, V>(ReferenceStrength.HARD, ReferenceStrength.HARD); + + 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)); } - - + //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testNullHandling() { resetFull(); - assertEquals(null, map.get(null)); - assertEquals(false, map.containsKey(null)); - assertEquals(false, map.containsValue(null)); - assertEquals(null, map.remove(null)); - assertEquals(false, map.entrySet().contains(null)); - assertEquals(false, map.keySet().contains(null)); - assertEquals(false, map.values().contains(null)); + assertEquals(null, getMap().get(null)); + assertEquals(false, getMap().containsKey(null)); + assertEquals(false, getMap().containsValue(null)); + assertEquals(null, getMap().remove(null)); + assertEquals(false, getMap().entrySet().contains(null)); + assertEquals(false, getMap().keySet().contains(null)); + assertEquals(false, getMap().values().contains(null)); try { - map.put(null, null); + getMap().put(null, null); fail(); } catch (NullPointerException ex) {} try { - map.put(new Object(), null); + getMap().put((K) new Object(), null); fail(); } catch (NullPointerException ex) {} try { - map.put(null, new Object()); + getMap().put(null, (V) new Object()); fail(); } catch (NullPointerException ex) {} } @@ -263,19 +266,20 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { } */ - WeakReference keyReference; - WeakReference valueReference; - - public Map buildRefMap() { - Object key = new Object(); - Object value = new Object(); - - keyReference = new WeakReference(key); - valueReference = new WeakReference(value); - - Map testMap = new ReferenceIdentityMap(ReferenceMap.WEAK, ReferenceMap.HARD, true); + WeakReference<K> keyReference; + WeakReference<V> valueReference; + + @SuppressWarnings("unchecked") + private Map<K, V> buildRefMap() { + K key = (K) new Object(); + V value = (V) new Object(); + + keyReference = new WeakReference<K>(key); + valueReference = new WeakReference<V>(value); + + Map<K, V> testMap = new ReferenceIdentityMap<K, V>(ReferenceStrength.WEAK, ReferenceStrength.HARD, true); testMap.put(key, value); - + assertEquals("In map", value, testMap.get(key)); assertNotNull("Weak reference released early (1)", keyReference.get()); assertNotNull("Weak reference released early (2)", valueReference.get()); @@ -285,29 +289,31 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap { /** Tests whether purge values setting works */ public void testPurgeValues() throws Exception { // many thanks to Juozas Baliuka for suggesting this method - Map testMap = buildRefMap(); - + Map<K, V> testMap = buildRefMap(); + int iterations = 0; int bytz = 2; - while(true) { + while (true) { System.gc(); - if(iterations++ > 50){ + if (iterations++ > 50) { fail("Max iterations reached before resource released."); } testMap.isEmpty(); - if( + if ( keyReference.get() == null && valueReference.get() == null) { break; - + } else { // create garbage: + @SuppressWarnings("unused") byte[] b = new byte[bytz]; bytz = bytz * 2; } } } + @SuppressWarnings("unused") private static void gc() { try { // trigger GC http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestReferenceMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestReferenceMap.java b/src/test/org/apache/commons/collections/map/TestReferenceMap.java index fbdae7b..d4c05d2 100644 --- a/src/test/org/apache/commons/collections/map/TestReferenceMap.java +++ b/src/test/org/apache/commons/collections/map/TestReferenceMap.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. @@ -22,16 +22,17 @@ import java.util.Map; import junit.framework.Test; import org.apache.commons.collections.BulkTest; +import org.apache.commons.collections.map.AbstractReferenceMap.ReferenceStrength; /** - * Tests for ReferenceMap. - * + * Tests for ReferenceMap. + * * @version $Revision$ $Date$ * * @author Paul Jack * @author Guilhem Lavaux */ -public class TestReferenceMap extends AbstractTestIterableMap { +public class TestReferenceMap<K, V> extends AbstractTestIterableMap<K, V> { public TestReferenceMap(String testName) { super(testName); @@ -46,9 +47,8 @@ public class TestReferenceMap extends AbstractTestIterableMap { junit.textui.TestRunner.main(testCaseName); } - public Map makeEmptyMap() { - ReferenceMap map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK); - return map; + public ReferenceMap<K, V> makeObject() { + return new ReferenceMap<K, V>(ReferenceStrength.WEAK, ReferenceStrength.WEAK); } public boolean isAllowNullKey() { @@ -64,6 +64,7 @@ public class TestReferenceMap extends AbstractTestIterableMap { } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testNullHandling() { resetFull(); assertEquals(null, map.get(null)); @@ -78,11 +79,11 @@ public class TestReferenceMap extends AbstractTestIterableMap { fail(); } catch (NullPointerException ex) {} try { - map.put(new Object(), null); + map.put((K) new Object(), null); fail(); } catch (NullPointerException ex) {} try { - map.put(null, new Object()); + map.put(null, (V) new Object()); fail(); } catch (NullPointerException ex) {} } @@ -198,19 +199,20 @@ public class TestReferenceMap extends AbstractTestIterableMap { } */ - WeakReference keyReference; - WeakReference valueReference; - - public Map buildRefMap() { - Object key = new Object(); - Object value = new Object(); - - keyReference = new WeakReference(key); - valueReference = new WeakReference(value); - - Map testMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true); + WeakReference<K> keyReference; + WeakReference<V> valueReference; + + @SuppressWarnings("unchecked") + public Map<K, V> buildRefMap() { + K key = (K) new Object(); + V value = (V) new Object(); + + keyReference = new WeakReference<K>(key); + valueReference = new WeakReference<V>(value); + + Map<K, V> testMap = new ReferenceMap<K, V>(ReferenceStrength.WEAK, ReferenceStrength.HARD, true); testMap.put(key, value); - + assertEquals("In map", value, testMap.get(key)); assertNotNull("Weak reference released early (1)", keyReference.get()); assertNotNull("Weak reference released early (2)", valueReference.get()); @@ -220,29 +222,29 @@ public class TestReferenceMap extends AbstractTestIterableMap { /** Tests whether purge values setting works */ public void testPurgeValues() throws Exception { // many thanks to Juozas Baliuka for suggesting this method - Map testMap = buildRefMap(); + Map<K, V> testMap = buildRefMap(); int iterations = 0; int bytz = 2; - while(true) { + while (true) { System.gc(); - if(iterations++ > 50){ + if (iterations++ > 50) { fail("Max iterations reached before resource released."); } testMap.isEmpty(); - if( - keyReference.get() == null && - valueReference.get() == null) { + if (keyReference.get() == null && valueReference.get() == null) { break; - + } else { // create garbage: - byte[] b = new byte[bytz]; + @SuppressWarnings("unused") + byte[] b = new byte[bytz]; bytz = bytz * 2; } } } + @SuppressWarnings("unused") private static void gc() { try { // trigger GC http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestSingletonMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestSingletonMap.java b/src/test/org/apache/commons/collections/map/TestSingletonMap.java index 26134a8..575f1bc 100644 --- a/src/test/org/apache/commons/collections/map/TestSingletonMap.java +++ b/src/test/org/apache/commons/collections/map/TestSingletonMap.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. @@ -17,7 +17,6 @@ package org.apache.commons.collections.map; import java.util.HashMap; -import java.util.Map; import junit.framework.Test; import junit.textui.TestRunner; @@ -25,21 +24,21 @@ import junit.textui.TestRunner; import org.apache.commons.collections.BoundedMap; import org.apache.commons.collections.BulkTest; import org.apache.commons.collections.KeyValue; +import org.apache.commons.collections.OrderedMap; /** * JUnit tests. - * + * * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestSingletonMap extends AbstractTestOrderedMap { +public class TestSingletonMap<K, V> extends AbstractTestOrderedMap<K, V> { private static final Integer ONE = new Integer(1); private static final Integer TWO = new Integer(2); private static final String TEN = "10"; - private static final String TWENTY = "20"; - + public TestSingletonMap(String testName) { super(testName); } @@ -47,18 +46,18 @@ public class TestSingletonMap extends AbstractTestOrderedMap { public static void main(String[] args) { TestRunner.run(suite()); } - + public static Test suite() { return BulkTest.makeSuite(TestSingletonMap.class); } //----------------------------------------------------------------------- - public Map makeEmptyMap() { + public OrderedMap<K, V> makeObject() { // need an empty singleton map, but thats not possible // use a ridiculous fake instead to make the tests pass - return UnmodifiableOrderedMap.decorate(ListOrderedMap.decorate(new HashMap())); + return UnmodifiableOrderedMap.decorate(ListOrderedMap.decorate(new HashMap<K, V>())); } - + public String[] ignoredTests() { // the ridiculous map above still doesn't pass these tests // but its not relevant, so we ignore them @@ -68,9 +67,9 @@ public class TestSingletonMap extends AbstractTestOrderedMap { }; } - - public Map makeFullMap() { - return new SingletonMap(ONE, TWO); + @SuppressWarnings("unchecked") + public SingletonMap<K, V> makeFullMap() { + return new SingletonMap<K, V>((K) ONE, (V) TWO); } public boolean isPutAddSupported() { @@ -81,30 +80,33 @@ public class TestSingletonMap extends AbstractTestOrderedMap { return false; } - public Object[] getSampleKeys() { - return new Object[] {ONE}; + @SuppressWarnings("unchecked") + public K[] getSampleKeys() { + return (K[]) new Object[] { ONE }; } - public Object[] getSampleValues() { - return new Object[] {TWO}; + @SuppressWarnings("unchecked") + public V[] getSampleValues() { + return (V[]) new Object[] { TWO }; } - public Object[] getNewSampleValues() { - return new Object[] {TEN}; + @SuppressWarnings("unchecked") + public V[] getNewSampleValues() { + return (V[]) new Object[] { TEN }; } //----------------------------------------------------------------------- public void testClone() { - SingletonMap map = new SingletonMap(ONE, TWO); + SingletonMap<K, V> map = makeFullMap(); assertEquals(1, map.size()); - SingletonMap cloned = (SingletonMap) map.clone(); + SingletonMap<K, V> cloned = map.clone(); assertEquals(1, cloned.size()); assertEquals(true, cloned.containsKey(ONE)); assertEquals(true, cloned.containsValue(TWO)); } public void testKeyValue() { - SingletonMap map = new SingletonMap(ONE, TWO); + SingletonMap<K, V> map = makeFullMap(); assertEquals(1, map.size()); assertEquals(ONE, map.getKey()); assertEquals(TWO, map.getValue()); @@ -112,7 +114,7 @@ public class TestSingletonMap extends AbstractTestOrderedMap { } public void testBoundedMap() { - SingletonMap map = new SingletonMap(ONE, TWO); + SingletonMap<K, V> map = makeFullMap(); assertEquals(1, map.size()); assertEquals(true, map.isFull()); assertEquals(1, map.maxSize()); @@ -123,16 +125,16 @@ public class TestSingletonMap extends AbstractTestOrderedMap { // public BulkTest bulkTestMapIterator() { // return new TestFlatMapIterator(); // } -// +// // public class TestFlatMapIterator extends AbstractTestOrderedMapIterator { // public TestFlatMapIterator() { // super("TestFlatMapIterator"); // } -// +// // public Object[] addSetValues() { // return TestSingletonMap.this.getNewSampleValues(); // } -// +// // public boolean supportsRemove() { // return TestSingletonMap.this.isRemoveSupported(); // } @@ -150,23 +152,23 @@ public class TestSingletonMap extends AbstractTestOrderedMap { // resetFull(); // return ((Flat3Map) TestSingletonMap.this.map).mapIterator(); // } -// +// // public Map getMap() { // // assumes makeFullMapIterator() called first // return TestSingletonMap.this.map; // } -// +// // public Map getConfirmedMap() { // // assumes makeFullMapIterator() called first // return TestSingletonMap.this.confirmed; // } -// +// // public void verify() { // super.verify(); // TestSingletonMap.this.verify(); // } // } - + public String getCompatibilityVersion() { return "3.1"; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java b/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java index ac96d87..a9c1c70 100644 --- a/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java +++ b/src/test/org/apache/commons/collections/map/TestStaticBucketMap.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. @@ -16,8 +16,6 @@ */ package org.apache.commons.collections.map; -import java.util.Map; - import junit.framework.Test; import org.apache.commons.collections.BulkTest; @@ -25,12 +23,12 @@ import org.apache.commons.collections.BulkTest; /** * Unit tests. * {@link StaticBucketMap}. - * + * * @version $Revision$ $Date$ - * + * * @author Michael A. Smith */ -public class TestStaticBucketMap extends AbstractTestMap { +public class TestStaticBucketMap<K, V> extends AbstractTestMap<K, V> { public TestStaticBucketMap(String name) { super(name); @@ -45,8 +43,8 @@ public class TestStaticBucketMap extends AbstractTestMap { junit.textui.TestRunner.main(testCaseName); } - public Map makeEmptyMap() { - return new StaticBucketMap(30); + public StaticBucketMap<K, V> makeObject() { + return new StaticBucketMap<K, V>(30); } public String[] ignoredTests() { @@ -60,9 +58,10 @@ public class TestStaticBucketMap extends AbstractTestMap { } // Bugzilla 37567 + @SuppressWarnings("unchecked") public void test_get_nullMatchesIncorrectly() { - StaticBucketMap map = new StaticBucketMap(17); - map.put(null, "A"); + StaticBucketMap<K, V> map = new StaticBucketMap<K, V>(17); + map.put(null, (V) "A"); assertEquals("A", map.get(null)); // loop so we find a string that is in the same bucket as the null for (int i = 'A'; i <= 'Z'; i++) { @@ -71,9 +70,10 @@ public class TestStaticBucketMap extends AbstractTestMap { } } + @SuppressWarnings("unchecked") public void test_containsKey_nullMatchesIncorrectly() { - StaticBucketMap map = new StaticBucketMap(17); - map.put(null, "A"); + StaticBucketMap<K, V> map = new StaticBucketMap<K, V>(17); + map.put(null, (V) "A"); assertEquals(true, map.containsKey(null)); // loop so we find a string that is in the same bucket as the null for (int i = 'A'; i <= 'Z'; i++) { @@ -82,9 +82,10 @@ public class TestStaticBucketMap extends AbstractTestMap { } } + @SuppressWarnings("unchecked") public void test_containsValue_nullMatchesIncorrectly() { - StaticBucketMap map = new StaticBucketMap(17); - map.put("A", null); + StaticBucketMap<K, V> map = new StaticBucketMap<K, V>(17); + map.put((K) "A", null); assertEquals(true, map.containsValue(null)); // loop so we find a string that is in the same bucket as the null for (int i = 'A'; i <= 'Z'; i++) { http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestTransformedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestTransformedMap.java b/src/test/org/apache/commons/collections/map/TestTransformedMap.java index 59e93ea..15f8a18 100644 --- a/src/test/org/apache/commons/collections/map/TestTransformedMap.java +++ b/src/test/org/apache/commons/collections/map/TestTransformedMap.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. @@ -23,6 +23,7 @@ import java.util.Set; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.collections.Transformer; import org.apache.commons.collections.TransformerUtils; import org.apache.commons.collections.collection.TestTransformedCollection; @@ -32,11 +33,11 @@ import org.apache.commons.collections.collection.TestTransformedCollection; * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestTransformedMap extends AbstractTestMap { - +public class TestTransformedMap<K, V> extends AbstractTestMap<K, V> { + public TestTransformedMap(String testName) { super(testName); } @@ -51,32 +52,38 @@ public class TestTransformedMap extends AbstractTestMap { } //----------------------------------------------------------------------- - public Map makeEmptyMap() { - return TransformedMap.decorate(new HashMap(), TransformerUtils.nopTransformer(), TransformerUtils.nopTransformer()); + public Map<K, V> makeObject() { + return TransformedMap.decorate(new HashMap<K, V>(), TransformerUtils.<K> nopTransformer(), + TransformerUtils.<V> nopTransformer()); } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testTransformedMap() { - Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; + Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" }; - Map map = TransformedMap.decorate(new HashMap(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER, null); + Map<K, V> map = TransformedMap + .decorate( + new HashMap<K, V>(), + (Transformer<? super K, ? extends K>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER, + null); assertEquals(0, map.size()); for (int i = 0; i < els.length; i++) { - map.put(els[i], els[i]); + map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); assertEquals(true, map.containsKey(new Integer((String) els[i]))); assertEquals(false, map.containsKey(els[i])); assertEquals(true, map.containsValue(els[i])); assertEquals(els[i], map.get(new Integer((String) els[i]))); } - + assertEquals(null, map.remove(els[0])); assertEquals(els[0], map.remove(new Integer((String) els[0]))); - + map = TransformedMap.decorate(new HashMap(), null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(0, map.size()); for (int i = 0; i < els.length; i++) { - map.put(els[i], els[i]); + map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); assertEquals(true, map.containsValue(new Integer((String) els[i]))); assertEquals(false, map.containsValue(els[i])); @@ -85,13 +92,13 @@ public class TestTransformedMap extends AbstractTestMap { } assertEquals(new Integer((String) els[0]), map.remove(els[0])); - + Set entrySet = map.entrySet(); Map.Entry[] array = (Map.Entry[]) entrySet.toArray(new Map.Entry[0]); array[0].setValue("66"); assertEquals(new Integer(66), array[0].getValue()); assertEquals(new Integer(66), map.get(array[0].getKey())); - + Map.Entry entry = (Map.Entry) entrySet.iterator().next(); entry.setValue("88"); assertEquals(new Integer(88), entry.getValue()); @@ -99,33 +106,43 @@ public class TestTransformedMap extends AbstractTestMap { } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testFactory_Decorate() { - Map base = new HashMap(); - base.put("A", "1"); - base.put("B", "2"); - base.put("C", "3"); - - Map trans = TransformedMap.decorate(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); + Map<K, V> base = new HashMap<K, V>(); + base.put((K) "A", (V) "1"); + base.put((K) "B", (V) "2"); + base.put((K) "C", (V) "3"); + + Map<K, V> trans = TransformedMap + .decorate( + base, + null, + (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); assertEquals("1", trans.get("A")); assertEquals("2", trans.get("B")); assertEquals("3", trans.get("C")); - trans.put("D", "4"); + trans.put((K) "D", (V) "4"); assertEquals(new Integer(4), trans.get("D")); } + @SuppressWarnings("unchecked") public void testFactory_decorateTransform() { - Map base = new HashMap(); - base.put("A", "1"); - base.put("B", "2"); - base.put("C", "3"); - - Map trans = TransformedMap.decorateTransform(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); + Map<K, V> base = new HashMap<K, V>(); + base.put((K) "A", (V) "1"); + base.put((K) "B", (V) "2"); + base.put((K) "C", (V) "3"); + + Map<K, V> trans = TransformedMap + .decorateTransform( + base, + null, + (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); assertEquals(new Integer(1), trans.get("A")); assertEquals(new Integer(2), trans.get("B")); assertEquals(new Integer(3), trans.get("C")); - trans.put("D", "4"); + trans.put((K) "D", (V) "4"); assertEquals(new Integer(4), trans.get("D")); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestTransformedSortedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestTransformedSortedMap.java b/src/test/org/apache/commons/collections/map/TestTransformedSortedMap.java index 4749c3c..0d52348 100644 --- a/src/test/org/apache/commons/collections/map/TestTransformedSortedMap.java +++ b/src/test/org/apache/commons/collections/map/TestTransformedSortedMap.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. @@ -24,6 +24,7 @@ import java.util.TreeMap; import junit.framework.Test; import org.apache.commons.collections.BulkTest; +import org.apache.commons.collections.Transformer; import org.apache.commons.collections.TransformerUtils; import org.apache.commons.collections.collection.TestTransformedCollection; @@ -33,11 +34,11 @@ import org.apache.commons.collections.collection.TestTransformedCollection; * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestTransformedSortedMap extends AbstractTestSortedMap { - +public class TestTransformedSortedMap<K, V> extends AbstractTestSortedMap<K, V> { + public TestTransformedSortedMap(String testName) { super(testName); } @@ -52,8 +53,11 @@ public class TestTransformedSortedMap extends AbstractTestSortedMap { } //----------------------------------------------------------------------- - public Map makeEmptyMap() { - return TransformedSortedMap.decorate(new TreeMap(), TransformerUtils.nopTransformer(), TransformerUtils.nopTransformer()); + @SuppressWarnings("unchecked") + public SortedMap<K, V> makeObject() { + return TransformedSortedMap.decorate(new TreeMap<K, V>(), + (Transformer<? super K, ? extends K>) TransformerUtils.nopTransformer(), + (Transformer<? super V, ? extends V>) TransformerUtils.nopTransformer()); } public boolean isSubMapViewsSerializable() { @@ -61,14 +65,19 @@ public class TestTransformedSortedMap extends AbstractTestSortedMap { return false; } - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testTransformedMap() { - Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; + Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" }; - Map map = TransformedSortedMap.decorate(new TreeMap(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER, null); + SortedMap<K, V> map = TransformedSortedMap + .decorate( + new TreeMap<K, V>(), + (Transformer<? super K, ? extends K>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER, + null); assertEquals(0, map.size()); for (int i = 0; i < els.length; i++) { - map.put(els[i], els[i]); + map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); assertEquals(true, map.containsKey(new Integer((String) els[i]))); try { @@ -78,17 +87,21 @@ public class TestTransformedSortedMap extends AbstractTestSortedMap { assertEquals(true, map.containsValue(els[i])); assertEquals(els[i], map.get(new Integer((String) els[i]))); } - + try { map.remove(els[0]); fail(); } catch (ClassCastException ex) {} assertEquals(els[0], map.remove(new Integer((String) els[0]))); - - map = TransformedSortedMap.decorate(new TreeMap(), null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); + + map = TransformedSortedMap + .decorate( + new TreeMap<K, V>(), + null, + (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(0, map.size()); for (int i = 0; i < els.length; i++) { - map.put(els[i], els[i]); + map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); assertEquals(true, map.containsValue(new Integer((String) els[i]))); assertEquals(false, map.containsValue(els[i])); @@ -97,47 +110,57 @@ public class TestTransformedSortedMap extends AbstractTestSortedMap { } assertEquals(new Integer((String) els[0]), map.remove(els[0])); - - Set entrySet = map.entrySet(); - Map.Entry[] array = (Map.Entry[]) entrySet.toArray(new Map.Entry[0]); - array[0].setValue("66"); + + Set<Map.Entry<K, V>> entrySet = map.entrySet(); + Map.Entry<K, V>[] array = (Map.Entry<K, V>[]) entrySet.toArray(new Map.Entry[0]); + array[0].setValue((V) "66"); assertEquals(new Integer(66), array[0].getValue()); assertEquals(new Integer(66), map.get(array[0].getKey())); - - Map.Entry entry = (Map.Entry) entrySet.iterator().next(); - entry.setValue("88"); + + Map.Entry<K, V> entry = entrySet.iterator().next(); + entry.setValue((V) "88"); assertEquals(new Integer(88), entry.getValue()); assertEquals(new Integer(88), map.get(entry.getKey())); } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testFactory_Decorate() { - SortedMap base = new TreeMap(); - base.put("A", "1"); - base.put("B", "2"); - base.put("C", "3"); - - SortedMap trans = TransformedSortedMap.decorate(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); + SortedMap<K, V> base = new TreeMap<K, V>(); + base.put((K) "A", (V) "1"); + base.put((K) "B", (V) "2"); + base.put((K) "C", (V) "3"); + + SortedMap<K, V> trans = TransformedSortedMap + .decorate( + base, + null, + (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); assertEquals("1", trans.get("A")); assertEquals("2", trans.get("B")); assertEquals("3", trans.get("C")); - trans.put("D", "4"); + trans.put((K) "D", (V) "4"); assertEquals(new Integer(4), trans.get("D")); } + @SuppressWarnings("unchecked") public void testFactory_decorateTransform() { - SortedMap base = new TreeMap(); - base.put("A", "1"); - base.put("B", "2"); - base.put("C", "3"); - - SortedMap trans = TransformedSortedMap.decorateTransform(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); + SortedMap<K, V> base = new TreeMap<K, V>(); + base.put((K) "A", (V) "1"); + base.put((K) "B", (V) "2"); + base.put((K) "C", (V) "3"); + + SortedMap<K, V> trans = TransformedSortedMap + .decorateTransform( + base, + null, + (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); assertEquals(new Integer(1), trans.get("A")); assertEquals(new Integer(2), trans.get("B")); assertEquals(new Integer(3), trans.get("C")); - trans.put("D", "4"); + trans.put((K) "D", (V) "4"); assertEquals(new Integer(4), trans.get("D")); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestUnmodifiableMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestUnmodifiableMap.java b/src/test/org/apache/commons/collections/map/TestUnmodifiableMap.java index 949a079..9eb2b8c 100644 --- a/src/test/org/apache/commons/collections/map/TestUnmodifiableMap.java +++ b/src/test/org/apache/commons/collections/map/TestUnmodifiableMap.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. @@ -22,66 +22,67 @@ import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.collections.IterableMap; import org.apache.commons.collections.Unmodifiable; /** - * Extension of {@link AbstractTestMap} for exercising the + * Extension of {@link AbstractTestMap} for exercising the * {@link UnmodifiableMap} implementation. * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Phil Steitz */ -public class TestUnmodifiableMap extends AbstractTestIterableMap{ - +public class TestUnmodifiableMap<K, V> extends AbstractTestIterableMap<K, V> { + public TestUnmodifiableMap(String testName) { super(testName); } - + public static Test suite() { return new TestSuite(TestUnmodifiableMap.class); } - + public static void main(String args[]) { String[] testCaseName = { TestUnmodifiableMap.class.getName()}; junit.textui.TestRunner.main(testCaseName); } - + //------------------------------------------------------------------- - - public Map makeEmptyMap() { - return UnmodifiableMap.decorate(new HashMap()); + + public IterableMap<K, V> makeObject() { + return (IterableMap<K, V>) UnmodifiableMap.decorate(new HashMap<K, V>()); } - + public boolean isPutChangeSupported() { return false; } - + public boolean isPutAddSupported() { return false; } - + public boolean isRemoveSupported() { return false; } - - public Map makeFullMap() { - Map m = new HashMap(); + + public IterableMap<K, V> makeFullMap() { + Map<K, V> m = new HashMap<K, V>(); addSampleMappings(m); - return UnmodifiableMap.decorate(m); + return (IterableMap<K, V>) UnmodifiableMap.decorate(m); } - + //----------------------------------------------------------------------- public void testUnmodifiable() { - assertTrue(makeEmptyMap() instanceof Unmodifiable); + assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable); } - + public void testDecorateFactory() { - Map map = makeFullMap(); + Map<K, V> map = makeFullMap(); assertSame(map, UnmodifiableMap.decorate(map)); - + try { UnmodifiableMap.decorate(null); fail(); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestUnmodifiableOrderedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestUnmodifiableOrderedMap.java b/src/test/org/apache/commons/collections/map/TestUnmodifiableOrderedMap.java index 9b831fe..74f4a9e 100644 --- a/src/test/org/apache/commons/collections/map/TestUnmodifiableOrderedMap.java +++ b/src/test/org/apache/commons/collections/map/TestUnmodifiableOrderedMap.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. @@ -17,7 +17,6 @@ package org.apache.commons.collections.map; import java.util.HashMap; -import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; @@ -26,63 +25,63 @@ import org.apache.commons.collections.OrderedMap; import org.apache.commons.collections.Unmodifiable; /** - * Extension of {@link AbstractTestOrderedMap} for exercising the + * Extension of {@link AbstractTestOrderedMap} for exercising the * {@link UnmodifiableOrderedMap} implementation. * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestUnmodifiableOrderedMap extends AbstractTestOrderedMap { - +public class TestUnmodifiableOrderedMap<K, V> extends AbstractTestOrderedMap<K, V> { + public TestUnmodifiableOrderedMap(String testName) { super(testName); } - + public static Test suite() { return new TestSuite(TestUnmodifiableOrderedMap.class); } - + public static void main(String args[]) { String[] testCaseName = { TestUnmodifiableOrderedMap.class.getName()}; junit.textui.TestRunner.main(testCaseName); } - + //------------------------------------------------------------------- - - public Map makeEmptyMap() { - return UnmodifiableOrderedMap.decorate(ListOrderedMap.decorate(new HashMap())); + + public OrderedMap<K, V> makeObject() { + return UnmodifiableOrderedMap.decorate(ListOrderedMap.decorate(new HashMap<K, V>())); } - + public boolean isPutChangeSupported() { return false; } - + public boolean isPutAddSupported() { return false; } - + public boolean isRemoveSupported() { return false; } - - public Map makeFullMap() { - OrderedMap m = ListOrderedMap.decorate(new HashMap()); + + public OrderedMap<K, V> makeFullMap() { + OrderedMap<K, V> m = ListOrderedMap.decorate(new HashMap<K, V>()); addSampleMappings(m); return UnmodifiableOrderedMap.decorate(m); } - + //----------------------------------------------------------------------- public void testUnmodifiable() { - assertTrue(makeEmptyMap() instanceof Unmodifiable); + assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable); } - + public void testDecorateFactory() { - Map map = makeFullMap(); - assertSame(map, UnmodifiableOrderedMap.decorate((OrderedMap) map)); - + OrderedMap<K, V> map = makeFullMap(); + assertSame(map, UnmodifiableOrderedMap.decorate(map)); + try { UnmodifiableOrderedMap.decorate(null); fail(); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestUnmodifiableSortedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestUnmodifiableSortedMap.java b/src/test/org/apache/commons/collections/map/TestUnmodifiableSortedMap.java index 3922b1b..eb155e9 100644 --- a/src/test/org/apache/commons/collections/map/TestUnmodifiableSortedMap.java +++ b/src/test/org/apache/commons/collections/map/TestUnmodifiableSortedMap.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. @@ -16,7 +16,6 @@ */ package org.apache.commons.collections.map; -import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; @@ -26,63 +25,63 @@ import junit.framework.TestSuite; import org.apache.commons.collections.Unmodifiable; /** - * Extension of {@link AbstractTestSortedMap} for exercising the + * Extension of {@link AbstractTestSortedMap} for exercising the * {@link UnmodifiableSortedMap} implementation. * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestUnmodifiableSortedMap extends AbstractTestSortedMap { - +public class TestUnmodifiableSortedMap<K, V> extends AbstractTestSortedMap<K, V> { + public TestUnmodifiableSortedMap(String testName) { super(testName); } - + public static Test suite() { return new TestSuite(TestUnmodifiableSortedMap.class); } - + public static void main(String args[]) { String[] testCaseName = { TestUnmodifiableSortedMap.class.getName()}; junit.textui.TestRunner.main(testCaseName); } - + //------------------------------------------------------------------- - - public Map makeEmptyMap() { - return UnmodifiableSortedMap.decorate(new TreeMap()); + + public SortedMap<K, V> makeObject() { + return UnmodifiableSortedMap.decorate(new TreeMap<K, V>()); } - + public boolean isPutChangeSupported() { return false; } - + public boolean isPutAddSupported() { return false; } - + public boolean isRemoveSupported() { return false; } - - public Map makeFullMap() { - SortedMap m = new TreeMap(); + + public SortedMap<K, V> makeFullMap() { + SortedMap<K, V> m = new TreeMap<K, V>(); addSampleMappings(m); return UnmodifiableSortedMap.decorate(m); } - + //----------------------------------------------------------------------- public void testUnmodifiable() { - assertTrue(makeEmptyMap() instanceof Unmodifiable); + assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable); } - + public void testDecorateFactory() { - Map map = makeFullMap(); - assertSame(map, UnmodifiableSortedMap.decorate((SortedMap) map)); - + SortedMap<K, V> map = makeFullMap(); + assertSame(map, UnmodifiableSortedMap.decorate(map)); + try { UnmodifiableSortedMap.decorate(null); fail(); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/set/AbstractTestSet.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/set/AbstractTestSet.java b/src/test/org/apache/commons/collections/set/AbstractTestSet.java index 77b37a8..46f1649 100644 --- a/src/test/org/apache/commons/collections/set/AbstractTestSet.java +++ b/src/test/org/apache/commons/collections/set/AbstractTestSet.java @@ -43,7 +43,7 @@ import org.apache.commons.collections.collection.AbstractTestCollection; * * @author Paul Jack */ -public abstract class AbstractTestSet extends AbstractTestCollection { +public abstract class AbstractTestSet<E> extends AbstractTestCollection<E> { /** * JUnit constructor. @@ -61,14 +61,13 @@ public abstract class AbstractTestSet extends AbstractTestCollection { public void verify() { super.verify(); - assertEquals("Sets should be equal", confirmed, collection); + assertEquals("Sets should be equal", getConfirmed(), getCollection()); assertEquals("Sets should have equal hashCodes", - confirmed.hashCode(), collection.hashCode()); - Collection set = makeConfirmedCollection(); - Iterator iterator = collection.iterator(); + getConfirmed().hashCode(), getCollection().hashCode()); + Collection<E> set = makeConfirmedCollection(); + Iterator<E> iterator = getCollection().iterator(); while (iterator.hasNext()) { - assertTrue("Set.iterator should only return unique elements", - set.add(iterator.next())); + assertTrue("Set.iterator should only return unique elements", set.add(iterator.next())); } } @@ -85,8 +84,8 @@ public abstract class AbstractTestSet extends AbstractTestCollection { * * @return a confirmed empty collection */ - public Collection makeConfirmedCollection() { - return new HashSet(); + public Collection<E> makeConfirmedCollection() { + return new HashSet<E>(); } /** @@ -94,8 +93,8 @@ public abstract class AbstractTestSet extends AbstractTestCollection { * * @return a confirmed full collection */ - public Collection makeConfirmedFullCollection() { - Collection set = makeConfirmedCollection(); + public Collection<E> makeConfirmedFullCollection() { + Collection<E> set = makeConfirmedCollection(); set.addAll(Arrays.asList(getFullElements())); return set; } @@ -105,7 +104,7 @@ public abstract class AbstractTestSet extends AbstractTestCollection { * * @return an empty set */ - public abstract Set makeEmptySet(); + public abstract Set<E> makeObject(); /** * Makes a full set by first creating an empty set and then adding @@ -115,68 +114,48 @@ public abstract class AbstractTestSet extends AbstractTestCollection { * * @return a full set */ - public Set makeFullSet() { - Set set = makeEmptySet(); + public Set<E> makeFullCollection() { + Set<E> set = makeObject(); set.addAll(Arrays.asList(getFullElements())); return set; } - /** - * Makes an empty collection by invoking {@link #makeEmptySet()}. - * - * @return an empty collection - */ - public final Collection makeCollection() { - return makeEmptySet(); - } - - /** - * Makes a full collection by invoking {@link #makeFullSet()}. - * - * @return a full collection - */ - public final Collection makeFullCollection() { - return makeFullSet(); - } - //----------------------------------------------------------------------- /** * Return the {@link AbstractTestCollection#collection} fixture, but cast as a Set. */ - public Set getSet() { - return (Set)collection; + public Set<E> getCollection() { + return (Set<E>) super.getCollection(); } /** * Return the {@link AbstractTestCollection#confirmed} fixture, but cast as a Set. */ - public Set getConfirmedSet() { - return (Set)confirmed; + public Set<E> getConfirmed() { + return (Set<E>) super.getConfirmed(); } //----------------------------------------------------------------------- /** * Tests {@link Set#equals(Object)}. */ + @SuppressWarnings("unchecked") public void testSetEquals() { resetEmpty(); - assertEquals("Empty sets should be equal", - getSet(), getConfirmedSet()); + assertEquals("Empty sets should be equal", getCollection(), getConfirmed()); verify(); - Collection set2 = makeConfirmedCollection(); - set2.add("foo"); - assertTrue("Empty set shouldn't equal nonempty set", - !getSet().equals(set2)); + Collection<E> set2 = makeConfirmedCollection(); + set2.add((E) "foo"); + assertTrue("Empty set shouldn't equal nonempty set", !getCollection().equals(set2)); resetFull(); - assertEquals("Full sets should be equal", getSet(), getConfirmedSet()); + assertEquals("Full sets should be equal", getCollection(), getConfirmed()); verify(); set2.clear(); set2.addAll(Arrays.asList(getOtherElements())); - assertTrue("Sets with different contents shouldn't be equal", - !getSet().equals(set2)); + assertTrue("Sets with different contents shouldn't be equal", !getCollection().equals(set2)); } /** @@ -185,11 +164,11 @@ public abstract class AbstractTestSet extends AbstractTestCollection { public void testSetHashCode() { resetEmpty(); assertEquals("Empty sets have equal hashCodes", - getSet().hashCode(), getConfirmedSet().hashCode()); + getCollection().hashCode(), getConfirmed().hashCode()); resetFull(); assertEquals("Equal sets have equal hashCodes", - getSet().hashCode(), getConfirmedSet().hashCode()); + getCollection().hashCode(), getConfirmed().hashCode()); } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java b/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java index 08ec512..0006d18 100644 --- a/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java +++ b/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java @@ -16,9 +16,7 @@ */ package org.apache.commons.collections.set; -import java.util.Collection; import java.util.Iterator; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -38,7 +36,7 @@ import org.apache.commons.collections.BulkTest; * @author Stephen Colebourne * @author Dieter Wimberger */ -public abstract class AbstractTestSortedSet extends AbstractTestSet { +public abstract class AbstractTestSortedSet<E> extends AbstractTestSet<E> { /** * JUnit constructor. @@ -59,10 +57,10 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { // Check that iterator returns elements in order and first() and last() // are consistent - Iterator colliter = collection.iterator(); - Iterator confiter = confirmed.iterator(); - Object first = null; - Object last = null; + Iterator<E> colliter = getCollection().iterator(); + Iterator<E> confiter = getConfirmed().iterator(); + E first = null; + E last = null; while (colliter.hasNext()) { if (first == null) { first = colliter.next(); @@ -72,11 +70,11 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { } assertEquals("Element appears to be out of order.", last, confiter.next()); } - if (collection.size() > 0) { + if (getCollection().size() > 0) { assertEquals("Incorrect element returned by first().", first, - ((SortedSet) collection).first()); + getCollection().first()); assertEquals("Incorrect element returned by last().", last, - ((SortedSet) collection).last()); + getCollection().last()); } } @@ -89,47 +87,56 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { return false; } + /** + * {@inheritDoc} + */ + @Override + public abstract SortedSet<E> makeObject(); + + /** + * {@inheritDoc} + */ + @Override + public SortedSet<E> makeFullCollection() { + return (SortedSet<E>) super.makeFullCollection(); + } + //----------------------------------------------------------------------- /** * Returns an empty {@link TreeSet} for use in modification testing. * * @return a confirmed empty collection */ - public Collection makeConfirmedCollection() { - return new TreeSet(); + public SortedSet<E> makeConfirmedCollection() { + return new TreeSet<E>(); } //----------------------------------------------------------------------- - /** - * Return the {@link AbstractTestCollection#confirmed} fixture, but cast as a - * SortedSet. - */ - public SortedSet getConfirmedSortedSet() { - return (SortedSet) confirmed; - } //----------------------------------------------------------------------- /** * Override to return comparable objects. */ - public Object[] getFullNonNullElements() { + @SuppressWarnings("unchecked") + public E[] getFullNonNullElements() { Object[] elements = new Object[30]; for (int i = 0; i < 30; i++) { elements[i] = new Integer(i + i + 1); } - return elements; + return (E[]) elements; } /** * Override to return comparable objects. */ - public Object[] getOtherNonNullElements() { + @SuppressWarnings("unchecked") + public E[] getOtherNonNullElements() { Object[] elements = new Object[30]; for (int i = 0; i < 30; i++) { elements[i] = new Integer(i + i + 2); } - return elements; + return (E[]) elements; } //----------------------------------------------------------------------- @@ -181,23 +188,24 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { return new TestSortedSetSubSet(lobound, false); } - public class TestSortedSetSubSet extends AbstractTestSortedSet { + public class TestSortedSetSubSet extends AbstractTestSortedSet<E> { private int m_Type; private int m_LowBound; private int m_HighBound; - private Object[] m_FullElements; - private Object[] m_OtherElements; + private E[] m_FullElements; + private E[] m_OtherElements; + @SuppressWarnings("unchecked") public TestSortedSetSubSet(int bound, boolean head) { super("TestSortedSetSubSet"); if (head) { //System.out.println("HEADSET"); m_Type = TYPE_HEADSET; m_HighBound = bound; - m_FullElements = new Object[bound]; + m_FullElements = (E[]) new Object[bound]; System.arraycopy(AbstractTestSortedSet.this.getFullElements(), 0, m_FullElements, 0, bound); - m_OtherElements = new Object[bound - 1]; + m_OtherElements = (E[]) new Object[bound - 1]; System.arraycopy(//src src_pos dst dst_pos length AbstractTestSortedSet.this.getOtherElements(), 0, m_OtherElements, 0, bound - 1); //System.out.println(new TreeSet(Arrays.asList(m_FullElements))); @@ -208,9 +216,9 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { m_LowBound = bound; Object[] allelements = AbstractTestSortedSet.this.getFullElements(); //System.out.println("bound = "+bound +"::length="+allelements.length); - m_FullElements = new Object[allelements.length - bound]; + m_FullElements = (E[]) new Object[allelements.length - bound]; System.arraycopy(allelements, bound, m_FullElements, 0, allelements.length - bound); - m_OtherElements = new Object[allelements.length - bound - 1]; + m_OtherElements = (E[]) new Object[allelements.length - bound - 1]; System.arraycopy(//src src_pos dst dst_pos length AbstractTestSortedSet.this.getOtherElements(), bound, m_OtherElements, 0, allelements.length - bound - 1); //System.out.println(new TreeSet(Arrays.asList(m_FullElements))); @@ -223,6 +231,7 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { } //type + @SuppressWarnings("unchecked") public TestSortedSetSubSet(int lobound, int hibound) { super("TestSortedSetSubSet"); //System.out.println("SUBSET"); @@ -231,9 +240,9 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { m_HighBound = hibound; int length = hibound - lobound; //System.out.println("Low=" + lobound + "::High=" + hibound + "::Length=" + length); - m_FullElements = new Object[length]; + m_FullElements = (E[]) new Object[length]; System.arraycopy(AbstractTestSortedSet.this.getFullElements(), lobound, m_FullElements, 0, length); - m_OtherElements = new Object[length - 1]; + m_OtherElements = (E[]) new Object[length - 1]; System.arraycopy(//src src_pos dst dst_pos length AbstractTestSortedSet.this.getOtherElements(), lobound, m_OtherElements, 0, length - 1); @@ -255,15 +264,15 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { return AbstractTestSortedSet.this.isFailFastSupported(); } - public Object[] getFullElements() { + public E[] getFullElements() { return m_FullElements; } - public Object[] getOtherElements() { + public E[] getOtherElements() { return m_OtherElements; } - private SortedSet getSubSet(SortedSet set) { - Object[] elements = AbstractTestSortedSet.this.getFullElements(); + private SortedSet<E> getSubSet(SortedSet<E> set) { + E[] elements = AbstractTestSortedSet.this.getFullElements(); switch (m_Type) { case TYPE_SUBSET : return set.subSet(elements[m_LowBound], elements[m_HighBound]); @@ -276,14 +285,12 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { } } - public Set makeEmptySet() { - SortedSet s = (SortedSet) AbstractTestSortedSet.this.makeEmptySet(); - return getSubSet(s); + public SortedSet<E> makeObject() { + return getSubSet(AbstractTestSortedSet.this.makeObject()); } - public Set makeFullSet() { - SortedSet s = (SortedSet) AbstractTestSortedSet.this.makeFullCollection(); - return getSubSet(s); + public SortedSet<E> makeFullCollection() { + return getSubSet(AbstractTestSortedSet.this.makeFullCollection()); } public boolean isTestSerialization() { @@ -306,4 +313,19 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet { } + /** + * {@inheritDoc} + */ + @Override + public SortedSet<E> getCollection() { + return (SortedSet<E>) super.getCollection(); + } + + /** + * {@inheritDoc} + */ + @Override + public SortedSet<E> getConfirmed() { + return (SortedSet<E>) super.getConfirmed(); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/set/TestCompositeSet.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/set/TestCompositeSet.java b/src/test/org/apache/commons/collections/set/TestCompositeSet.java index 9ae926c..680f7df 100644 --- a/src/test/org/apache/commons/collections/set/TestCompositeSet.java +++ b/src/test/org/apache/commons/collections/set/TestCompositeSet.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. @@ -27,7 +27,7 @@ import junit.framework.TestSuite; import org.apache.commons.collections.collection.CompositeCollection; /** - * Extension of {@link AbstractTestSet} for exercising the + * Extension of {@link AbstractTestSet} for exercising the * {@link CompositeSet} implementation. * * @since Commons Collections 3.0 @@ -37,110 +37,117 @@ import org.apache.commons.collections.collection.CompositeCollection; * @author Phil Steitz */ -public class TestCompositeSet extends AbstractTestSet { +public class TestCompositeSet<E> extends AbstractTestSet<E> { public TestCompositeSet(String name) { super(name); } - + public static Test suite() { return new TestSuite(TestCompositeSet.class); } - - public Set makeEmptySet() { - final HashSet contained = new HashSet(); - CompositeSet set = new CompositeSet(contained); - set.setMutator(new CompositeSet.SetMutator() { - public void resolveCollision(CompositeSet comp, Set existing, - Set added, Collection intersects) { + + public CompositeSet<E> makeObject() { + final HashSet<E> contained = new HashSet<E>(); + CompositeSet<E> set = new CompositeSet<E>(contained); + set.setMutator(new CompositeSet.SetMutator<E>() { + public void resolveCollision(CompositeSet<E> comp, Set<E> existing, + Set<E> added, Collection<E> intersects) { throw new IllegalArgumentException(); } - - public boolean add(CompositeCollection composite, - List collections, Object obj) { + + public boolean add(CompositeCollection<E> composite, + List<Collection<E>> collections, E obj) { return contained.add(obj); } - - public boolean addAll(CompositeCollection composite, - List collections, Collection coll) { + + public boolean addAll(CompositeCollection<E> composite, + List<Collection<E>> collections, Collection<? extends E> coll) { return contained.addAll(coll); } - - public boolean remove(CompositeCollection composite, - List collections, Object obj) { + + public boolean remove(CompositeCollection<E> composite, + List<Collection<E>> collections, Object obj) { return contained.remove(obj); } }); return set; } - - public Set buildOne() { - HashSet set = new HashSet(); - set.add("1"); - set.add("2"); + + @SuppressWarnings("unchecked") + public Set<E> buildOne() { + HashSet<E> set = new HashSet<E>(); + set.add((E) "1"); + set.add((E) "2"); return set; } - - public Set buildTwo() { - HashSet set = new HashSet(); - set.add("3"); - set.add("4"); + + @SuppressWarnings("unchecked") + public Set<E> buildTwo() { + HashSet<E> set = new HashSet<E>(); + set.add((E) "3"); + set.add((E) "4"); return set; } - + + @SuppressWarnings("unchecked") public void testContains() { - CompositeSet set = new CompositeSet(new Set[]{buildOne(), buildTwo()}); + CompositeSet<E> set = new CompositeSet<E>(new Set[]{ buildOne(), buildTwo() }); assertTrue(set.contains("1")); } - + + @SuppressWarnings("unchecked") public void testRemoveUnderlying() { - Set one = buildOne(); - Set two = buildTwo(); - CompositeSet set = new CompositeSet(new Set[]{one, two}); + Set<E> one = buildOne(); + Set<E> two = buildTwo(); + CompositeSet<E> set = new CompositeSet<E>(new Set[] { one, two }); one.remove("1"); assertFalse(set.contains("1")); - + two.remove("3"); assertFalse(set.contains("3")); } - + + @SuppressWarnings("unchecked") public void testRemoveComposited() { - Set one = buildOne(); - Set two = buildTwo(); - CompositeSet set = new CompositeSet(new Set[]{one, two}); + Set<E> one = buildOne(); + Set<E> two = buildTwo(); + CompositeSet<E> set = new CompositeSet<E>(new Set[] { one, two }); set.remove("1"); assertFalse(one.contains("1")); - + set.remove("3"); assertFalse(one.contains("3")); } - + + @SuppressWarnings("unchecked") public void testFailedCollisionResolution() { - Set one = buildOne(); - Set two = buildTwo(); - CompositeSet set = new CompositeSet(new Set[]{one, two}); - set.setMutator(new CompositeSet.SetMutator() { - public void resolveCollision(CompositeSet comp, Set existing, - Set added, Collection intersects) { + Set<E> one = buildOne(); + Set<E> two = buildTwo(); + CompositeSet<E> set = new CompositeSet<E>(new Set[] { one, two }); + set.setMutator(new CompositeSet.SetMutator<E>() { + public void resolveCollision(CompositeSet<E> comp, Set<E> existing, + Set<E> added, Collection<E> intersects) { + //noop } - - public boolean add(CompositeCollection composite, - List collections, Object obj) { + + public boolean add(CompositeCollection<E> composite, + List<Collection<E>> collections, E obj) { throw new UnsupportedOperationException(); } - - public boolean addAll(CompositeCollection composite, - List collections, Collection coll) { + + public boolean addAll(CompositeCollection<E> composite, + List<Collection<E>> collections, Collection<? extends E> coll) { throw new UnsupportedOperationException(); } - - public boolean remove(CompositeCollection composite, - List collections, Object obj) { + + public boolean remove(CompositeCollection<E> composite, + List<Collection<E>> collections, Object obj) { throw new UnsupportedOperationException(); } }); - - HashSet three = new HashSet(); - three.add("1"); + + HashSet<E> three = new HashSet<E>(); + three.add((E) "1"); try { set.addComposited(three); fail("IllegalArgumentException should have been thrown"); @@ -149,22 +156,23 @@ public class TestCompositeSet extends AbstractTestSet { // expected } } - + + @SuppressWarnings("unchecked") public void testAddComposited() { - Set one = buildOne(); - Set two = buildTwo(); - CompositeSet set = new CompositeSet(); + Set<E> one = buildOne(); + Set<E> two = buildTwo(); + CompositeSet<E> set = new CompositeSet<E>(); set.addComposited(one, two); - CompositeSet set2 = new CompositeSet(buildOne()); + CompositeSet<E> set2 = new CompositeSet<E>(buildOne()); set2.addComposited(buildTwo()); assertTrue(set.equals(set2)); - HashSet set3 = new HashSet(); - set3.add("1"); - set3.add("2"); - set3.add("3"); - HashSet set4 = new HashSet(); - set4.add("4"); - CompositeSet set5 = new CompositeSet(set3); + HashSet<E> set3 = new HashSet<E>(); + set3.add((E) "1"); + set3.add((E) "2"); + set3.add((E) "3"); + HashSet<E> set4 = new HashSet<E>(); + set4.add((E) "4"); + CompositeSet<E> set5 = new CompositeSet<E>(set3); set5.addComposited(set4); assertTrue(set.equals(set5)); try {