1 4 package com.terracotta.session.util; 5 6 import java.util.NoSuchElementException ; 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 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 nsee) { 25 } 27 } 28 29 public void testEmptyArray() { 30 StringArrayEnumeration sae = null; 31 try { 32 sae = new StringArrayEnumeration(new String [0]); 33 } catch (Exception 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 nsee) { 42 } 44 } 45 46 public void testNonEmptyArray() { 47 final String [] array = new String [] { "1", "2", "3" }; 48 StringArrayEnumeration sae = null; 49 try { 50 sae = new StringArrayEnumeration(array); 51 } catch (Exception 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 s = (String )sae.nextElement(); 58 assertEquals(array[i], s); 59 } 60 assertFalse(sae.hasMoreElements()); 61 try { 62 sae.nextElement(); 63 fail("expected exception"); 64 } catch (NoSuchElementException nsee) { 65 } 67 } 68 69 } 70 | Popular Tags |