1   /* $Header$
2    * $Revision$
3    * $Date$
4    *
5    * ====================================================================
6    *
7    * Copyright 2005 Elliotte Rusty Harold.
8    * All rights reserved.
9    *
10   * Redistribution and use in source and binary forms, with or without
11   * modification, are permitted provided that the following conditions are
12   * met:
13   * 
14   *   * Redistributions of source code must retain the above copyright
15   *     notice, this list of conditions and the following disclaimer.
16   * 
17   *   * Redistributions in binary form must reproduce the above copyright
18   *     notice, this list of conditions and the following disclaimer in the
19   *     documentation and/or other materials provided with the distribution.
20   * 
21   *   * Neither the name of the Jaxen Project nor the names of its
22   *     contributors may be used to endorse or promote products derived 
23   *     from this software without specific prior written permission.
24   * 
25   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26   * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28   * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
29   * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36   *
37   * ====================================================================
38   * This software consists of voluntary contributions made by many 
39   * individuals on behalf of the Jaxen Project and was originally 
40   * created by bob mcwhirter <bob@werken.com> and 
41   * James Strachan <jstrachan@apache.org>.  For more information on the 
42   * Jaxen Project, please see <http://www.jaxen.org/>.
43   * 
44   * $Id$
45   */
46  package org.jaxen.test;
47  
48  import java.util.Iterator;
49  import java.util.NoSuchElementException;
50  
51  import javax.xml.parsers.DocumentBuilderFactory;
52  import javax.xml.parsers.ParserConfigurationException;
53  
54  import org.jaxen.util.AncestorOrSelfAxisIterator;
55  import org.w3c.dom.Document;
56  
57  import junit.framework.TestCase;
58  
59  public class AncestorOrSelfAxisIteratorTest extends TestCase {
60  
61      private Iterator iterator;
62  
63      public AncestorOrSelfAxisIteratorTest(String name) {
64          super(name);
65      }
66      
67      protected void setUp() throws ParserConfigurationException {
68          
69          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
70          factory.setNamespaceAware(true);
71          Document doc = factory.newDocumentBuilder().newDocument();
72          doc.appendChild(doc.createElement("root"));
73          
74          iterator = new AncestorOrSelfAxisIterator(doc, new org.jaxen.dom.DocumentNavigator());
75          
76      }
77      
78      
79      public void testNoInfiniteLoops() {
80       
81          iterator.next();
82          try {
83              iterator.next();
84              fail("Iterated twice");   
85          }
86          catch (NoSuchElementException ex) {
87          }
88          
89      }
90      
91      
92      public void testRemove() {
93          
94          try {
95              iterator.remove();
96              fail("Removed from iterator");   
97          }
98          catch (UnsupportedOperationException ex) {
99          }
100         
101     }
102     
103 }