--- old/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java 2015-01-28 03:06:26.677982362 -0800 +++ new/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java 2015-01-28 03:06:26.597972193 -0800 @@ -24,10 +24,15 @@ package javax.xml.xpath.ptests; import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL; + +import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactoryConfigurationException; + import jaxp.library.JAXPBaseTest; -import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.Assert.assertNotNull; + +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** @@ -43,6 +48,62 @@ * Invalid URL not able to create a XPath factory. */ private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1"; + + private static final String URI = "http://java.sun.com/jaxp/xpath/dom"; + private static final String XPATH_FACTORY_CLASSNAME = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"; + + @DataProvider(name = "parameters") + public Object[][] getValidateParameters() { + return new Object[][] { { URI, XPATH_FACTORY_CLASSNAME, null }, { URI, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader() } }; + } + + /* + * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String + * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName + * points to correct implementation of javax.xml.xpath.XPathFactory , should + * return newInstance of XPathFactory + */ + @Test(dataProvider = "parameters") + public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException { + XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader); + XPath xpath = xpf.newXPath(); + assertNotNull(xpath); + } + + @DataProvider(name = "invalid-parameters") + public Object[][] getInvalidateParameters() { + return new Object[][] { { URI, null, null }, { URI, null, this.getClass().getClassLoader() } }; + } + + /* + * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String + * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is + * null , should throw XPathFactoryConfigurationException + */ + @Test(expectedExceptions = XPathFactoryConfigurationException.class, dataProvider = "invalid-parameters") + public void testNewInstanceWithNullFactoryClassName(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException { + XPathFactory.newInstance(uri, factoryClassName, classLoader); + } + + /* + * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String + * factoryClassName, java.lang.ClassLoader classLoader) uri is null , should + * throw NPE + */ + @Test(expectedExceptions = NullPointerException.class) + public void testNewInstanceWithNullUri() throws XPathFactoryConfigurationException { + XPathFactory.newInstance(null, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader()); + } + + /* + * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String + * factoryClassName, java.lang.ClassLoader classLoader) uri is empty, should + * throw IllegalArgumentException + */ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNewInstanceWithEmptyUri() throws XPathFactoryConfigurationException { + XPathFactory.newInstance("", XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader()); + } /** * Test for constructor - XPathFactory.newInstance().