You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2009/01/12 05:48:04 UTC
svn commit: r733623 - in
/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util:
ArrayListTest.java LinkedListTest.java VectorTest.java
Author: qiuxx
Date: Sun Jan 11 20:48:04 2009
New Revision: 733623
URL: http://svn.apache.org/viewvc?rev=733623&view=rev
Log:
Apply for HARMONY-5809,([classlib][luni] Add some testcases for Vector, ArrayList and LinkedList)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/VectorTest.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java?rev=733623&r1=733622&r2=733623&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java Sun Jan 11 20:48:04 2009
@@ -59,6 +59,16 @@
// Test for method java.util.ArrayList(int)
ArrayList al = new ArrayList(5);
assertEquals("Incorrect arrayList created", 0, al.size());
+
+ al = new ArrayList(0);
+ assertEquals("Incorrect arrayList created", 0, al.size());
+
+ try {
+ al = new ArrayList(-1);
+ fail("Should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // Excepted
+ }
}
/**
@@ -92,9 +102,68 @@
assertNull("Should have returned null", alist.get(25));
assertTrue("Should have returned the old item from slot 25", alist
.get(26) == oldItem);
+
+ alist.add(0, o = new Object());
+ assertEquals("Failed to add Object", alist.get(0), o);
+ assertEquals(alist.get(1), objArray[0]);
+ assertEquals(alist.get(2), objArray[1]);
+
+ oldItem = alist.get(0);
+ alist.add(0, null);
+ assertNull("Should have returned null", alist.get(0));
+ assertEquals("Should have returned the old item from slot 0", alist
+ .get(1), oldItem);
+
+ try {
+ alist.add(-1, new Object());
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ alist.add(-1, null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ alist.add(alist.size() + 1, new Object());
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ alist.add(alist.size() + 1, null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
+ * @tests java.util.ArrayList#add(int, java.lang.Object)
+ */
+ public void test_addILjava_lang_Object_2() {
+ Object o = new Object();
+ int size = alist.size();
+ alist.add(size, o);
+ assertEquals("Failed to add Object", alist.get(size), o);
+ assertEquals(alist.get(size - 2), objArray[size - 2]);
+ assertEquals(alist.get(size - 1), objArray[size - 1]);
+
+ alist.remove(size);
+
+ size = alist.size();
+ alist.add(size, null);
+ assertNull("Should have returned null", alist.get(size));
+ assertEquals(alist.get(size - 2), objArray[size - 2]);
+ assertEquals(alist.get(size - 1), objArray[size - 1]);
+ }
+
+ /**
* @tests java.util.ArrayList#add(java.lang.Object)
*/
public void test_addLjava_lang_Object() {
@@ -209,6 +278,48 @@
assertEquals(strings[i], list1.get(i + integers.length - 1));
}
}
+
+ /**
+ * @tests java.util.ArrayList#addAll(int, java.util.Collection)
+ */
+ public void test_addAllILjava_util_Collection_3() {
+ ArrayList obj = new ArrayList();
+ obj.addAll(0, obj);
+ obj.addAll(obj.size(), obj);
+ try {
+ obj.addAll(-1, obj);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ obj.addAll(obj.size() + 1, obj);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ obj.addAll(0, null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Excepted
+ }
+
+ try {
+ obj.addAll(obj.size() + 1, null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ obj.addAll((int) -1, (Collection) null);
+ fail("IndexOutOfBoundsException expected");
+ } catch (IndexOutOfBoundsException e) {
+ }
+ }
public void test_addAllCollectionOfQextendsE() {
// Regression for HARMONY-539
@@ -261,6 +372,13 @@
assertTrue("Item at slot 103 is wrong: " + alist.get(102), alist
.get(102) == i.next());
+ try {
+ alist.addAll(null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Excepted
+ }
+
// Regression test for Harmony-3481
ArrayList<Integer> originalList = new ArrayList<Integer>(12);
for (int j = 0; j < 12; j++) {
@@ -445,6 +563,58 @@
}
/**
+ * @tests {@link java.util.ArrayList#removeRange(int, int)}
+ */
+ public void test_removeRange() {
+ MockArrayList mylist = new MockArrayList();
+ mylist.removeRange(0, 0);
+
+ try {
+ mylist.removeRange(0, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ int[] data = { 1, 2, 3 };
+ for (int i = 0; i < data.length; i++) {
+ mylist.add(i, data[i]);
+ }
+
+ mylist.removeRange(0, 1);
+ assertEquals(data[1], mylist.get(0));
+ assertEquals(data[2], mylist.get(1));
+
+ try {
+ mylist.removeRange(-1, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ mylist.removeRange(0, -1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ mylist.removeRange(1, 0);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ mylist.removeRange(2, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+ }
+
+ /**
* @tests java.util.ArrayList#remove(int)
*/
public void test_removeI() {
@@ -504,6 +674,38 @@
assertNull("Setting to null did not work", alist.get(50));
assertTrue("Setting increased the list's size to: " + alist.size(),
alist.size() == 100);
+
+ obj = new Object();
+ alist.set(0, obj);
+ assertTrue("Failed to set object", alist.get(0) == obj);
+
+ try {
+ alist.set(-1, obj);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ alist.set(alist.size(), obj);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ alist.set(-1, null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ alist.set(alist.size(), null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -674,6 +876,10 @@
public int size() {
return 0;
}
+
+ public void removeRange(int start, int end) {
+ super.removeRange(start, end);
+ }
}
public void test_subclassing() {
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java?rev=733623&r1=733622&r2=733623&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java Sun Jan 11 20:48:04 2009
@@ -75,6 +75,34 @@
ll.get(51) == objArray[50] && (ll.get(52) == objArray[51]));
ll.add(50, null);
assertNull("Did not add null correctly", ll.get(50));
+
+ try {
+ ll.add(-1, "Test");
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ ll.add(-1, null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ ll.add(ll.size() + 1, "Test");
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ ll.add(ll.size() + 1, null);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -120,6 +148,13 @@
assertEquals("d) List w/nulls not added correctly",
"Booga", ll.get(53));
assertNull("e) List w/nulls not added correctly", ll.get(54));
+
+ try {
+ ll.addAll(50, null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Excepted
+ }
}
/**
@@ -169,6 +204,13 @@
assertEquals("d) List w/nulls not added correctly",
"Booga", ll.get(203));
assertNull("e) List w/nulls not added correctly", ll.get(204));
+
+ try {
+ ll.addAll(null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Excepted
+ }
}
/**
@@ -249,6 +291,18 @@
} catch (IndexOutOfBoundsException e) {
}
}
+
+ /**
+ * @tests {@link java.util.LinkedList#peek()}
+ */
+ public void test_peek() {
+ LinkedList list = new LinkedList();
+
+ assertNull("Should return null if this list is empty", list.peek());
+
+ assertEquals("Returned incorrect first element", ll.peek(),objArray[0]);
+ assertEquals("Peek remove the head (first element) of this list", ll.getFirst(), objArray[0]);
+ }
/**
* @tests java.util.LinkedList#getFirst()
@@ -257,6 +311,14 @@
// Test for method java.lang.Object java.util.LinkedList.getFirst()
assertTrue("Returned incorrect first element", ll.getFirst().equals(
objArray[0]));
+
+ LinkedList list = new LinkedList();
+ try {
+ list.getFirst();
+ fail("Shoule throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // Excepted
+ }
}
/**
@@ -266,6 +328,14 @@
// Test for method java.lang.Object java.util.LinkedList.getLast()
assertTrue("Returned incorrect first element", ll.getLast().equals(
objArray[objArray.length - 1]));
+
+ LinkedList list = new LinkedList();
+ try {
+ list.getLast();
+ fail("Shoule throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // Excepted
+ }
}
/**
@@ -389,6 +459,14 @@
ll.removeFirst();
assertTrue("Failed to remove first element",
ll.getFirst() != objArray[0]);
+
+ LinkedList list = new LinkedList();
+ try {
+ list.removeFirst();
+ fail("Shoule throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // Excepted
+ }
}
/**
@@ -399,6 +477,14 @@
ll.removeLast();
assertTrue("Failed to remove last element",
ll.getLast() != objArray[objArray.length - 1]);
+
+ LinkedList list = new LinkedList();
+ try {
+ list.removeLast();
+ fail("Shoule throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // Excepted
+ }
}
/**
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/VectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/VectorTest.java?rev=733623&r1=733622&r2=733623&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/VectorTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/VectorTest.java Sun Jan 11 20:48:04 2009
@@ -89,6 +89,20 @@
grow.addElement("four");
assertEquals("Wrong size", 4, grow.size());
assertEquals("Wrong capacity", 6, grow.capacity());
+
+ Vector emptyVector = new Vector(0, 0);
+ emptyVector.addElement("one");
+ assertEquals("Wrong size", 1, emptyVector.size());
+ emptyVector.addElement("two");
+ emptyVector.addElement("three");
+ assertEquals("Wrong size", 3, emptyVector.size());
+
+ try {
+ Vector negativeVector = new Vector(-1, 0);
+ fail("Should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // Excepted
+ }
}
/**
@@ -178,6 +192,20 @@
.get(51));
assertNull("Wrong element at position 52--wanted null",
tVector.get(52));
+
+ try {
+ v.addAll(0, null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Excepted
+ }
+
+ try {
+ v.addAll(-1, null);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -209,6 +237,13 @@
.get(vSize + 1));
assertNull("Wrong element at last position--wanted null", tVector
.get(vSize + 2));
+
+ try {
+ v.addAll(null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Excepted
+ }
}
/**
@@ -419,6 +454,33 @@
.capacity());
v = new Vector(100);
assertEquals("ensureCapacity reduced capacity", 100, v.capacity());
+
+ v.ensureCapacity(150);
+ assertEquals(
+ "ensuieCapacity failed to set to be twice the old capacity",
+ 200, v.capacity());
+
+ v = new Vector(9, -1);
+ v.ensureCapacity(20);
+ assertEquals("ensureCapacity failed to set to be minCapacity", 20, v
+ .capacity());
+ v.ensureCapacity(15);
+ assertEquals("ensureCapacity reduced capacity", 20, v.capacity());
+ v.ensureCapacity(35);
+ assertEquals(
+ "ensuieCapacity failed to set to be twice the old capacity",
+ 40, v.capacity());
+
+ v = new Vector(9, 4);
+ v.ensureCapacity(11);
+ assertEquals("ensureCapacity failed to set correct capacity", 13, v
+ .capacity());
+ v.ensureCapacity(5);
+ assertEquals("ensureCapacity reduced capacity", 13, v.capacity());
+ v.ensureCapacity(20);
+ assertEquals(
+ "ensuieCapacity failed to set to be twice the old capacity",
+ 20, v.capacity());
}
/**
@@ -436,6 +498,10 @@
assertTrue("c) Equal vectors returned false", tVector.equals(v));
tVector.removeElementAt(22);
assertTrue("d) UnEqual vectors returned true", !tVector.equals(v));
+ assertTrue("e) Equal vectors returned false", tVector.equals(tVector));
+ assertFalse("f) UnEqual vectors returned true", tVector
+ .equals(new Object()));
+ assertFalse("g) Unequal vectors returned true", tVector.equals(null));
}
/**
@@ -448,6 +514,14 @@
tVector.insertElementAt(null, 0);
assertNull("Returned incorrect firstElement--wanted null", tVector
.firstElement());
+
+ Vector v = new Vector();
+ try {
+ v.firstElement();
+ fail("Should throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // Excepted
+ }
}
/**
@@ -540,6 +614,34 @@
.equals(prevElement));
v.insertElementAt(null, 20);
assertNull("null not inserted", v.elementAt(20));
+
+ try {
+ tVector.insertElementAt("Inserted Element", -1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.insertElementAt(null, -1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.insertElementAt("Inserted Element", tVector.size() + 1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.insertElementAt(null, tVector.size() + 1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -594,6 +696,14 @@
tVector.addElement(null);
assertNull("Incorrect last element returned--wanted null", tVector
.lastElement());
+
+ Vector vector = new Vector();
+ try {
+ vector.lastElement();
+ fail("Should throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // Excepted
+ }
}
/**
@@ -661,18 +771,41 @@
*/
public void test_removeI() {
// Test for method java.lang.Object java.util.Vector.remove(int)
- tVector.remove(36);
- assertTrue("Contained element after remove", !tVector
+ Object removeElement = tVector.get(36);
+ Object result = tVector.remove(36);
+ assertFalse("Contained element after remove", tVector
.contains("Test 36"));
+ assertEquals("Should return the element that was removed",
+ removeElement, result);
assertEquals("Failed to decrement size after remove",
99, tVector.size());
tVector.add(20, null);
- tVector.remove(19);
+ removeElement = tVector.get(19);
+ result = tVector.remove(19);
assertNull("Didn't move null element over", tVector.get(19));
- tVector.remove(19);
+ assertEquals("Should return the element that was removed",
+ removeElement, result);
+ removeElement = tVector.get(19);
+ result = tVector.remove(19);
assertNotNull("Didn't remove null element", tVector.get(19));
+ assertEquals("Should return the element that was removed",
+ removeElement, result);
assertEquals("Failed to decrement size after removing null", 98, tVector
.size());
+
+ try {
+ tVector.remove(-1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.remove(tVector.size());
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -758,13 +891,86 @@
public void test_removeElementAtI() {
// Test for method void java.util.Vector.removeElementAt(int)
Vector v = vectorClone(tVector);
+ int size = v.size();
v.removeElementAt(50);
assertEquals("Failed to remove element", -1, v.indexOf("Test 50", 0));
+ assertEquals("Test 51", v.get(50));
+ assertEquals(size - 1, v.size());
+
tVector.insertElementAt(null, 60);
+ assertNull(tVector.get(60));
+ size = tVector.size();
tVector.removeElementAt(60);
assertNotNull("Element at 60 should not be null after removal", tVector
.elementAt(60));
+ assertEquals(size - 1, tVector.size());
+
+ try {
+ tVector.removeElementAt(-1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.removeElementAt(tVector.size());
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
+
+ /**
+ * @tests {@link java.util.Vector#removeRange(int, int)}
+ */
+ public void test_removeRange() {
+ MockVector myVector = new MockVector();
+ myVector.removeRange(0, 0);
+
+ try {
+ myVector.removeRange(0, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ int[] data = { 1, 2, 3, 4 };
+ for (int i = 0; i < data.length; i++) {
+ myVector.add(i, data[i]);
+ }
+
+ myVector.removeRange(0, 2);
+ assertEquals(data[2], myVector.get(0));
+ assertEquals(data[3], myVector.get(1));
+
+ try {
+ myVector.removeRange(-1, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ myVector.removeRange(0, -1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ myVector.removeRange(1, 0);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ myVector.removeRange(2, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Excepted
+ }
+ }
/**
* @tests java.util.Vector#retainAll(java.util.Collection)
@@ -789,8 +995,47 @@
// Test for method java.lang.Object java.util.Vector.set(int,
// java.lang.Object)
Object o = new Object();
- tVector.set(23, o);
+ Object previous = tVector.get(23);
+ Object result = tVector.set(23, o);
+ assertEquals(
+ "Should return the element previously at the specified position",
+ previous, result);
assertTrue("Failed to set Object", tVector.get(23) == o);
+
+ previous = tVector.get(0);
+ result = tVector.set(0, null);
+ assertEquals(
+ "Should return the element previously at the specified position",
+ previous, result);
+ assertNull("Failed to set Object", tVector.get(0));
+
+ try {
+ tVector.set(-1, o);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.set(-1, null);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.set(tVector.size(), o);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ tVector.set(tVector.size(), null);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -803,6 +1048,37 @@
v.setElementAt("Inserted Element", 99);
assertEquals("Element not set", "Inserted Element", ((String) v.elementAt(99))
);
+
+ v.setElementAt(null, 0);
+ assertNull("Null element not set", v.elementAt(0));
+
+ try {
+ v.setElementAt("Inserted Element", -1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ v.setElementAt(null, -1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ v.setElementAt("Inserted Element", v.size());
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
+
+ try {
+ v.setElementAt(null, v.size());
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -811,8 +1087,32 @@
public void test_setSizeI() {
// Test for method void java.util.Vector.setSize(int)
Vector v = vectorClone(tVector);
+ int oldSize = v.size();
+ Object preElement = v.get(10);
v.setSize(10);
assertEquals("Failed to set size", 10, v.size());
+ assertEquals(
+ "All components at index newSize and greater should be discarded",
+ -1, v.indexOf(preElement));
+ try {
+ v.get(oldSize - 1);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted;
+ }
+
+ oldSize = v.size();
+ v.setSize(20);
+ assertEquals("Failed to set size", 20, v.size());
+ for (int i = oldSize; i < v.size(); i++) {
+ assertNull(v.get(i));
+ }
+
+ try {
+ v.setSize(-1);
+ fail("Should throw ArrayIndexOutOfBoundsException");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Excepted
+ }
}
/**
@@ -983,6 +1283,10 @@
public synchronized int size() {
return 0;
}
+
+ public void removeRange(int start, int end) {
+ super.removeRange(start, end);
+ }
}
/**