View Javadoc
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.FilteredEnumeration;
10  import org.melati.poem.util.EnumUtils;
11  
12  import junit.framework.TestCase;
13  
14  /**
15   * @author timp
16   * @since 7 June 2007
17   *
18   */
19  public class FilteredEnumerationTest extends TestCase {
20  
21    FilteredEnumeration<String> it;
22    
23    /**
24     * @param name
25     */
26    public FilteredEnumerationTest(String name) {
27      super(name);
28    }
29  
30    /** 
31     * {@inheritDoc}
32     * @see junit.framework.TestCase#setUp()
33     */
34    protected void setUp() throws Exception {
35      super.setUp();
36      Vector<String> v = new Vector<String>();
37      v.add("a");
38      v.add("b");
39      v.add("c");
40      v.add("d");
41      v.add("e");
42      it = new FilteredEnumeration<String>(v.elements()) {
43        public boolean isIncluded(String o) {
44          return o.compareTo("c") <= 0;
45        }
46      };
47    }
48  
49    /** 
50     * {@inheritDoc}
51     * @see junit.framework.TestCase#tearDown()
52     */
53    protected void tearDown() throws Exception {
54      super.tearDown();
55    }
56  
57    /**
58     * Test method for {@link org.melati.poem.util.FilteredEnumeration#FilteredEnumeration(java.util.Enumeration)}.
59     */
60    public void testFilteredEnumeration() {
61      assertEquals(3, EnumUtils.vectorOf(it).size());
62    }
63  
64    /**
65     * Test method for {@link org.melati.poem.util.FilteredEnumeration#hasMoreElements()}.
66     */
67    public void testHasMoreElements() {
68      
69    }
70  
71    /**
72     * Test method for {@link org.melati.poem.util.FilteredEnumeration#nextElement()}.
73     */
74    public void testNextElement() {
75      
76    }
77  
78    /**
79     * Test method for {@link org.melati.poem.util.FilteredEnumeration#skip()}.
80     */
81    public void testSkip() {
82      it.skip();
83      it.skip();
84      it.skip();
85      try { 
86        it.skip();
87        fail("Should have blown up");
88      } catch (NoSuchElementException e) { 
89        e = null;
90      }
91      try { 
92        it.nextElement();    
93      } catch (NoSuchElementException e) { 
94        e = null;
95      }
96    }
97  
98  }