< prev index next >

test/javax/xml/jaxp/unittest/javax/xml/xpath/Bug4991857.java

Print this page
rev 670 : [mq]: 8061549


  33 import org.w3c.dom.Document;
  34 
  35 
  36 /*
  37  * @bug 4991857
  38  * @summary XPath.evaluate(...) throws XPathExpressionException when context is null and expression refers to the context.
  39  */
  40 public class Bug4991857 {
  41 
  42     Document d = null;
  43 
  44     XPathFactory xpathFactory = XPathFactory.newInstance();
  45 
  46     @Test
  47     public void testXPath09() throws Exception {
  48         try {
  49             XPath xpath = xpathFactory.newXPath();
  50             Assert.assertNotNull(xpath);
  51 
  52             Double result = (Double) xpath.evaluate("1+2", d, XPathConstants.NUMBER);
  53         } catch (XPathExpressionException _) {
  54             Assert.fail("Unexpected XPathExpressionException thrown");
  55         }
  56     }
  57 
  58     @Test
  59     public void testXPath10() throws Exception {
  60         try {
  61             XPath xpath = xpathFactory.newXPath();
  62             Assert.assertNotNull(xpath);
  63 
  64             xpath.evaluate(".", d, XPathConstants.STRING);
  65             Assert.fail("XPathExpressionException not thrown");
  66         } catch (XPathExpressionException e) {
  67             // Expected exception as context node is null
  68         }
  69     }
  70 
  71     @Test
  72     public void testXPath11() throws Exception {
  73         try {


  33 import org.w3c.dom.Document;
  34 
  35 
  36 /*
  37  * @bug 4991857
  38  * @summary XPath.evaluate(...) throws XPathExpressionException when context is null and expression refers to the context.
  39  */
  40 public class Bug4991857 {
  41 
  42     Document d = null;
  43 
  44     XPathFactory xpathFactory = XPathFactory.newInstance();
  45 
  46     @Test
  47     public void testXPath09() throws Exception {
  48         try {
  49             XPath xpath = xpathFactory.newXPath();
  50             Assert.assertNotNull(xpath);
  51 
  52             Double result = (Double) xpath.evaluate("1+2", d, XPathConstants.NUMBER);
  53         } catch (XPathExpressionException unused) {
  54             Assert.fail("Unexpected XPathExpressionException thrown");
  55         }
  56     }
  57 
  58     @Test
  59     public void testXPath10() throws Exception {
  60         try {
  61             XPath xpath = xpathFactory.newXPath();
  62             Assert.assertNotNull(xpath);
  63 
  64             xpath.evaluate(".", d, XPathConstants.STRING);
  65             Assert.fail("XPathExpressionException not thrown");
  66         } catch (XPathExpressionException e) {
  67             // Expected exception as context node is null
  68         }
  69     }
  70 
  71     @Test
  72     public void testXPath11() throws Exception {
  73         try {
< prev index next >