1
2
3
4 package org.melati.poem.util.test;
5
6 import java.util.NoSuchElementException;
7 import java.util.Vector;
8
9 import org.melati.poem.util.LimitedEnumeration;
10
11 import junit.framework.TestCase;
12
13
14
15
16
17
18 public class LimitedEnumerationTest extends TestCase {
19
20
21
22
23 public LimitedEnumerationTest(String name) {
24 super(name);
25 }
26 LimitedEnumeration<String> it;
27 LimitedEnumeration<String> it2;
28
29
30
31
32 protected void setUp() throws Exception {
33 super.setUp();
34 Vector<String> them = new Vector<String>();
35 them.add("a");
36 them.add("b");
37 them.add("c");
38 them.add("d");
39 it = new LimitedEnumeration<String>(them.elements(),2);
40 it2 = new LimitedEnumeration<String>(new LimitedEnumeration<String>(them.elements(),2),2);
41 }
42
43
44
45
46
47 protected void tearDown() throws Exception {
48 super.tearDown();
49 }
50
51
52
53
54 public void testLimitedEnumeration() {
55 }
56
57
58
59
60 public void testHasMoreElements() {
61 assertTrue(it.hasMoreElements());
62 }
63
64
65
66
67 public void testNextElement() {
68 assertEquals("a", it.nextElement());
69 assertEquals("b", it.nextElement());
70 try {
71 assertEquals("c", it.nextElement());
72 fail("Should have bombed");
73 } catch (NoSuchElementException e) {
74 e = null;
75 }
76 }
77
78
79
80
81 public void testSkip() {
82 it.skip();
83 assertEquals("b", it.nextElement());
84 try {
85 it.nextElement();
86 fail("Should have bombed");
87 } catch (NoSuchElementException e) {
88 e = null;
89 }
90 try {
91 it.skip();
92 fail("Should have bombed");
93 } catch (NoSuchElementException e) {
94 e = null;
95 }
96 it2.skip();
97 assertEquals("b", it2.nextElement());
98 try {
99 it2.skip();
100 } catch (NoSuchElementException e) {
101 e = null;
102 }
103
104 }
105
106 }