KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > terracotta > session > util > StringArrayEnumerationTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.terracotta.session.util;
5
6 import java.util.NoSuchElementException JavaDoc;
7
8 import junit.framework.TestCase;
9
10 public class StringArrayEnumerationTest extends TestCase {
11
12   public void testNullArray() {
13     StringArrayEnumeration sae = null;
14     try {
15       sae = new StringArrayEnumeration(null);
16     } catch (Exception JavaDoc e) {
17       e.printStackTrace();
18       fail("unexpected Exception: " + e);
19     }
20     assertFalse(sae.hasMoreElements());
21     try {
22       sae.nextElement();
23       fail("expected exception");
24     } catch (NoSuchElementException JavaDoc nsee) {
25       // ok
26
}
27   }
28
29   public void testEmptyArray() {
30     StringArrayEnumeration sae = null;
31     try {
32       sae = new StringArrayEnumeration(new String JavaDoc[0]);
33     } catch (Exception JavaDoc e) {
34       e.printStackTrace();
35       fail("unexpected Exception: " + e);
36     }
37     assertFalse(sae.hasMoreElements());
38     try {
39       sae.nextElement();
40       fail("expected exception");
41     } catch (NoSuchElementException JavaDoc nsee) {
42       // ok
43
}
44   }
45
46   public void testNonEmptyArray() {
47     final String JavaDoc[] array = new String JavaDoc[] { "1", "2", "3" };
48     StringArrayEnumeration sae = null;
49     try {
50       sae = new StringArrayEnumeration(array);
51     } catch (Exception JavaDoc e) {
52       e.printStackTrace();
53       fail("unexpected Exception: " + e);
54     }
55     for (int i = 0; i < array.length; i++) {
56       assertTrue(sae.hasMoreElements());
57       String JavaDoc s = (String JavaDoc)sae.nextElement();
58       assertEquals(array[i], s);
59     }
60     assertFalse(sae.hasMoreElements());
61     try {
62       sae.nextElement();
63       fail("expected exception");
64     } catch (NoSuchElementException JavaDoc nsee) {
65       // ok
66
}
67   }
68
69 }
70
Popular Tags