1 /* $Header$ 2 * $Revision$ 3 * $Date$ 4 * 5 * ==================================================================== 6 * 7 * Copyright (C) 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 12 * are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer. 16 * 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions, and the disclaimer that follows 19 * these conditions in the documentation and/or other materials 20 * provided with the distribution. 21 * 22 * 3. The name "Jaxen" must not be used to endorse or promote products 23 * derived from this software without prior written permission. For 24 * written permission, please contact license@jaxen.org. 25 * 26 * 4. Products derived from this software may not be called "Jaxen", nor 27 * may "Jaxen" appear in their name, without prior written permission 28 * from the Jaxen Project Management (pm@jaxen.org). 29 * 30 * In addition, we request (but do not require) that you include in the 31 * end-user documentation provided with the redistribution and/or in the 32 * software itself an acknowledgement equivalent to the following: 33 * "This product includes software developed by the 34 * Jaxen Project (http://www.jaxen.org/)." 35 * Alternatively, the acknowledgment may be graphical using the logos 36 * available at http://www.jaxen.org/ 37 * 38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 * DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT 42 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 49 * SUCH DAMAGE. 50 * 51 * ==================================================================== 52 * This software consists of voluntary contributions made by many 53 * individuals on behalf of the Jaxen Project and was originally 54 * created by bob mcwhirter <bob@werken.com> and 55 * James Strachan <jstrachan@apache.org>. For more information on the 56 * Jaxen Project, please see <http://www.jaxen.org/>. 57 * 58 * $Id$ 59 */ 60 package org.jaxen.util; 61 62 import java.util.Iterator; 63 import java.util.NoSuchElementException; 64 65 import javax.xml.parsers.DocumentBuilderFactory; 66 import javax.xml.parsers.ParserConfigurationException; 67 68 import org.w3c.dom.Document; 69 70 import junit.framework.TestCase; 71 72 public class AncestorOrSelfAxisIteratorTest extends TestCase { 73 74 private Iterator iterator; 75 76 public AncestorOrSelfAxisIteratorTest(String name) { 77 super(name); 78 } 79 80 protected void setUp() throws ParserConfigurationException { 81 82 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 83 factory.setNamespaceAware(true); 84 Document doc = factory.newDocumentBuilder().newDocument(); 85 doc.appendChild(doc.createElement("root")); 86 87 iterator = new AncestorOrSelfAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); 88 89 } 90 91 92 public void testNoInfiniteLoops() { 93 94 iterator.next(); 95 try { 96 iterator.next(); 97 fail("Iterated twice"); 98 } 99 catch (NoSuchElementException ex) { 100 } 101 102 } 103 104 105 public void testRemove() { 106 107 try { 108 iterator.remove(); 109 fail("Removed from iterator"); 110 } 111 catch (UnsupportedOperationException ex) { 112 } 113 114 } 115 116 }