diff --git a/src/test/org/apache/commons/collections/set/TestCompositeSet.java b/src/test/org/apache/commons/collections/set/TestCompositeSet.java index 1c93b458e..3a791e896 100644 --- a/src/test/org/apache/commons/collections/set/TestCompositeSet.java +++ b/src/test/org/apache/commons/collections/set/TestCompositeSet.java @@ -16,17 +16,18 @@ */ package org.apache.commons.collections.set; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.collection.CompositeCollection; -import java.util.Set; -import java.util.HashSet; -import java.util.Collection; - /** - * Extension of {@link AbstractTestSet} for exercising the + * Extension of {@link AbstractTestSet} for exercising the * {@link CompositeSet} implementation. * * @since Commons Collections 3.0 @@ -36,90 +37,97 @@ import java.util.Collection; * @author Phil Steitz */ -public class TestCompositeSet extends AbstractTestSet { +public class TestCompositeSet extends AbstractTestSet { 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); + + public CompositeSet makeObject() { + final HashSet contained = new HashSet(); + CompositeSet set = new CompositeSet(contained); set.setMutator( new EmptySetMutator(contained) ); return set; } - - public Set buildOne() { - HashSet set = new HashSet(); - set.add("1"); - set.add("2"); + + @SuppressWarnings("unchecked") + public Set buildOne() { + HashSet set = new HashSet(); + 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 buildTwo() { + HashSet set = new HashSet(); + set.add((E) "3"); + set.add((E) "4"); return set; } - + + @SuppressWarnings("unchecked") public void testContains() { - CompositeSet set = new CompositeSet(new Set[]{buildOne(), buildTwo()}); + CompositeSet set = new CompositeSet(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 one = buildOne(); + Set two = buildTwo(); + CompositeSet set = new CompositeSet(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 one = buildOne(); + Set two = buildTwo(); + CompositeSet set = new CompositeSet(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 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) { + //noop } - - public boolean add(CompositeCollection composite, - Collection[] collections, Object obj) { + + public boolean add(CompositeCollection composite, + List> collections, E obj) { throw new UnsupportedOperationException(); } - - public boolean addAll(CompositeCollection composite, - Collection[] collections, Collection coll) { + + public boolean addAll(CompositeCollection composite, + List> collections, Collection coll) { throw new UnsupportedOperationException(); } - - public boolean remove(CompositeCollection composite, - Collection[] collections, Object obj) { + + public boolean remove(CompositeCollection composite, + List> collections, Object obj) { throw new UnsupportedOperationException(); } }); - - HashSet three = new HashSet(); - three.add("1"); + + HashSet three = new HashSet(); + three.add((E) "1"); try { set.addComposited(three); fail("IllegalArgumentException should have been thrown"); @@ -128,22 +136,23 @@ public class TestCompositeSet extends AbstractTestSet { // expected } } - + + @SuppressWarnings("unchecked") public void testAddComposited() { - Set one = buildOne(); - Set two = buildTwo(); - CompositeSet set = new CompositeSet(); + Set one = buildOne(); + Set two = buildTwo(); + CompositeSet set = new CompositeSet(); set.addComposited(one, two); - CompositeSet set2 = new CompositeSet(buildOne()); + CompositeSet set2 = new CompositeSet(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 set3 = new HashSet(); + set3.add((E) "1"); + set3.add((E) "2"); + set3.add((E) "3"); + HashSet set4 = new HashSet(); + set4.add((E) "4"); + CompositeSet set5 = new CompositeSet(set3); set5.addComposited(set4); assertTrue(set.equals(set5)); try {