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.jaxen.UnsupportedAxisException; 69 import org.w3c.dom.Document; 70 71 import junit.framework.TestCase; 72 73 public class FollowingSiblingAxisIteratorTest extends TestCase { 74 75 private Iterator iterator; 76 77 public FollowingSiblingAxisIteratorTest(String name) { 78 super(name); 79 } 80 81 protected void setUp() throws ParserConfigurationException, UnsupportedAxisException { 82 83 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 84 factory.setNamespaceAware(true); 85 Document doc = factory.newDocumentBuilder().newDocument(); 86 doc.appendChild(doc.createElement("root")); 87 88 iterator = new FollowingSiblingAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); 89 90 } 91 92 93 public void testNoInfiniteLoops() { 94 95 try { 96 iterator.next(); 97 fail("Iterated too far"); 98 } 99 catch (NoSuchElementException ex) { 100 pass(); 101 } 102 103 } 104 105 106 private void pass() { 107 // Just to make checkstyle and the like happy 108 } 109 110 public void testRemove() { 111 112 try { 113 iterator.remove(); 114 fail("Removed from descendant axis iterator"); 115 } 116 catch (UnsupportedOperationException ex) { 117 pass(); 118 } 119 120 } 121 122 }