1 package junit.samples; 2 3 import junit.framework.*; 4 import java.util.Vector ; 5 6 10 public class VectorTest extends TestCase { 11 protected Vector fEmpty; 12 protected Vector fFull; 13 14 public static void main (String [] args) { 15 junit.textui.TestRunner.run (suite()); 16 } 17 protected void setUp() { 18 fEmpty= new Vector (); 19 fFull= new Vector (); 20 fFull.addElement(new Integer (1)); 21 fFull.addElement(new Integer (2)); 22 fFull.addElement(new Integer (3)); 23 } 24 public static Test suite() { 25 return new TestSuite(VectorTest.class); 26 } 27 public void testCapacity() { 28 int size= fFull.size(); 29 for (int i= 0; i < 100; i++) 30 fFull.addElement(new Integer (i)); 31 assertTrue(fFull.size() == 100+size); 32 } 33 public void testClone() { 34 Vector clone= (Vector )fFull.clone(); 35 assertTrue(clone.size() == fFull.size()); 36 assertTrue(clone.contains(new Integer (1))); 37 } 38 public void testContains() { 39 assertTrue(fFull.contains(new Integer (1))); 40 assertTrue(!fEmpty.contains(new Integer (1))); 41 } 42 public void testElementAt() { 43 Integer i= (Integer )fFull.elementAt(0); 44 assertTrue(i.intValue() == 1); 45 46 try { 47 fFull.elementAt(fFull.size()); 48 } catch (ArrayIndexOutOfBoundsException e) { 49 return; 50 } 51 fail("Should raise an ArrayIndexOutOfBoundsException"); 52 } 53 public void testRemoveAll() { 54 fFull.removeAllElements(); 55 fEmpty.removeAllElements(); 56 assertTrue(fFull.isEmpty()); 57 assertTrue(fEmpty.isEmpty()); 58 } 59 public void testRemoveElement() { 60 fFull.removeElement(new Integer (3)); 61 assertTrue(!fFull.contains(new Integer (3)) ); 62 } 63 } | Popular Tags |