/* * Written by Doug Lea and Martin Buchholz with assistance from * members of JCP JSR-166 Expert Group and released to the public * domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ import java.util.Vector; import java.util.Collection; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; public class VectorTest extends JSR166TestCase { public static void main(String[] args) { main(suite(), args); } public static Test suite() { class Implementation implements CollectionImplementation { public Class klazz() { return Vector.class; } public List emptyCollection() { return new Vector(); } public Object makeElement(int i) { return i; } public boolean isConcurrent() { return false; } public boolean permitsNulls() { return true; } } class SubListImplementation extends Implementation { public List emptyCollection() { return super.emptyCollection().subList(0, 0); } } return newTestSuite( VectorTest.class, CollectionTest.testSuite(new Implementation()), CollectionTest.testSuite(new SubListImplementation())); } /** * tests for setSize() */ public void testSetSize() { Vector v = new Vector(); for (int n : new int[] { 100, 5, 50 }) { v.setSize(n); assertEquals(n, v.size()); assertNull(v.get(0)); assertNull(v.get(n - 1)); assertThrows(ArrayIndexOutOfBoundsException.class, () -> v.setSize(-1)); assertEquals(n, v.size()); assertNull(v.get(0)); assertNull(v.get(n - 1)); } } }