1 9 10 package test.dom4j.xpath; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.XPath; 16 import test.dom4j.AbstractTestCase; 17 18 23 public class TestBadPath extends AbstractTestCase { 24 25 String [] paths = { 26 "+", 27 "/foo/bar/", 28 }; 29 30 public static void main( String [] args ) { 31 TestRunner.run( suite() ); 32 } 33 34 public static Test suite() { 35 return new TestSuite( TestBadPath.class ); 36 } 37 38 public TestBadPath(String name) { 39 super(name); 40 } 41 42 public void testBadPaths() throws Exception { 45 for ( int i = 0, size = paths.length; i < size; i++ ) { 46 String path = paths[i]; 47 testBadPath( path ); 48 } 49 } 50 51 protected void testBadPath(String path) throws Exception { 52 try { 53 document.selectObject( path ); 54 55 fail( "Should have thrown exception for: " + path ); 56 } 57 catch (Exception e) { 58 log( "Successfully caught: " + e ); 59 } 60 try { 61 XPath xpath = document.createXPath( path ); 62 63 fail( "Should have thrown exception for: " + path ); 64 } 65 catch (Exception e) { 66 log( "Successfully caught: " + e ); 67 } 68 } 69 } 70 71 72 73 74 118 | Popular Tags |