From 7e3f2dfbee952b11d78bc4c07690a0b1fd1ac41c Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 12 Nov 2005 12:40:01 +0000 Subject: [PATCH] Improve tests from 37338 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@332769 13f79535-47bb-0310-9956-ffa450edef68 --- .../collections/set/TestListOrderedSet.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/org/apache/commons/collections/set/TestListOrderedSet.java b/src/test/org/apache/commons/collections/set/TestListOrderedSet.java index de7da9223..d597825f7 100644 --- a/src/test/org/apache/commons/collections/set/TestListOrderedSet.java +++ b/src/test/org/apache/commons/collections/set/TestListOrderedSet.java @@ -130,7 +130,6 @@ public class TestListOrderedSet extends AbstractTestSet { public void testListAddIndexed() { ListOrderedSet set = (ListOrderedSet) makeEmptySet(); - List view = set.asList(); set.add(ZERO); set.add(TWO); @@ -166,6 +165,38 @@ public class TestListOrderedSet extends AbstractTestSet { assertSame(ONE, set.get(3)); } + public void testListAddReplacing() { + ListOrderedSet set = (ListOrderedSet) makeEmptySet(); + A a = new A(); + B b = new B(); + set.add(a); + assertEquals(1, set.size()); + set.add(b); // will match but not replace A as equal + assertEquals(1, set.size()); + assertSame(a, set.getSet().iterator().next()); + assertSame(a, set.iterator().next()); + assertSame(a, set.get(0)); + assertSame(a, set.asList().get(0)); + } + + static class A { + public boolean equals(Object obj) { + return (obj instanceof A || obj instanceof B); + } + public int hashCode() { + return 1; + } + } + + static class B { + public boolean equals(Object obj) { + return (obj instanceof A || obj instanceof B); + } + public int hashCode() { + return 1; + } + } + public void testDecorator() { try { ListOrderedSet.decorate((List) null);