From 1e7b7fc64c68111899f035228fdda98357b502ee Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Tue, 15 Sep 2009 05:57:45 +0000 Subject: [PATCH] Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956. Also see the following revisions: ------------------------------------------------------------------------ r471580 | scolebourne | 2006-11-05 16:22:53 -0800 (Sun, 05 Nov 2006) | 1 line Generify CompositeCollection ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815137 13f79535-47bb-0310-9956-ffa450edef68 --- .../collections/set/TestCompositeSet.java | 137 ++++++++++-------- 1 file changed, 73 insertions(+), 64 deletions(-) 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 {