Improve tests

from 37338

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@332769 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-11-12 12:40:01 +00:00
parent 8e3968cd11
commit 7e3f2dfbee
1 changed files with 32 additions and 1 deletions

View File

@ -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);