01: package org.junit.samples;
02:
03: import static org.junit.Assert.assertTrue;
04:
05: import java.util.ArrayList;
06: import java.util.List;
07:
08: import junit.framework.JUnit4TestAdapter;
09: import org.junit.Before;
10: import org.junit.BeforeClass;
11: import org.junit.Ignore;
12: import org.junit.Test;
13:
14: /**
15: * A sample test case, testing {@link java.util.Vector}.
16: *
17: */
18: public class ListTest {
19: protected List<Integer> fEmpty;
20: protected List<Integer> fFull;
21: protected static List<Integer> fgHeavy;
22:
23: public static void main(String... args) {
24: junit.textui.TestRunner.run(suite());
25: }
26:
27: @BeforeClass
28: public static void setUpOnce() {
29: fgHeavy = new ArrayList<Integer>();
30: for (int i = 0; i < 1000; i++)
31: fgHeavy.add(i);
32: }
33:
34: @Before
35: public void setUp() {
36: fEmpty = new ArrayList<Integer>();
37: fFull = new ArrayList<Integer>();
38: fFull.add(1);
39: fFull.add(2);
40: fFull.add(3);
41: }
42:
43: public static junit.framework.Test suite() {
44: return new JUnit4TestAdapter(ListTest.class);
45: }
46:
47: @Ignore("not today")
48: @Test
49: public void capacity() {
50: int size = fFull.size();
51: for (int i = 0; i < 100; i++)
52: fFull.add(i);
53: assertTrue(fFull.size() == 100 + size);
54: }
55:
56: @Test
57: public void testCopy() {
58: List<Integer> copy = new ArrayList<Integer>(fFull.size());
59: copy.addAll(fFull);
60: assertTrue(copy.size() == fFull.size());
61: assertTrue(copy.contains(1));
62: }
63:
64: @Test
65: public void contains() {
66: assertTrue(fFull.contains(1));
67: assertTrue(!fEmpty.contains(1));
68: }
69:
70: @Test(expected=IndexOutOfBoundsException.class)
71: public void elementAt() {
72: int i = fFull.get(0);
73: assertTrue(i == 1);
74: fFull.get(fFull.size()); // Should throw IndexOutOfBoundsException
75: }
76:
77: @Test
78: public void removeAll() {
79: fFull.removeAll(fFull);
80: fEmpty.removeAll(fEmpty);
81: assertTrue(fFull.isEmpty());
82: assertTrue(fEmpty.isEmpty());
83: }
84:
85: @Test
86: public void removeElement() {
87: fFull.remove(new Integer(3));
88: assertTrue(!fFull.contains(3));
89: }
90: }
|