KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > samples > VectorTest


1 package junit.samples;
2
3 import junit.framework.*;
4 import java.util.Vector JavaDoc;
5
6 /**
7  * A sample test case, testing <code>java.util.Vector</code>.
8  *
9  */

10 public class VectorTest extends TestCase {
11     protected Vector JavaDoc fEmpty;
12     protected Vector JavaDoc fFull;
13
14     public static void main (String JavaDoc[] args) {
15         junit.textui.TestRunner.run (suite());
16     }
17     protected void setUp() {
18         fEmpty= new Vector JavaDoc();
19         fFull= new Vector JavaDoc();
20         fFull.addElement(new Integer JavaDoc(1));
21         fFull.addElement(new Integer JavaDoc(2));
22         fFull.addElement(new Integer JavaDoc(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 JavaDoc(i));
31         assertTrue(fFull.size() == 100+size);
32     }
33     public void testClone() {
34         Vector JavaDoc clone= (Vector JavaDoc)fFull.clone();
35         assertTrue(clone.size() == fFull.size());
36         assertTrue(clone.contains(new Integer JavaDoc(1)));
37     }
38     public void testContains() {
39         assertTrue(fFull.contains(new Integer JavaDoc(1)));
40         assertTrue(!fEmpty.contains(new Integer JavaDoc(1)));
41     }
42     public void testElementAt() {
43         Integer JavaDoc i= (Integer JavaDoc)fFull.elementAt(0);
44         assertTrue(i.intValue() == 1);
45
46         try {
47             fFull.elementAt(fFull.size());
48         } catch (ArrayIndexOutOfBoundsException JavaDoc 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 JavaDoc(3));
61         assertTrue(!fFull.contains(new Integer JavaDoc(3)) );
62     }
63 }
Popular Tags