< prev index next >

test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest02.java

Print this page

        

@@ -21,263 +21,251 @@
  * questions.
  */
 
 package javax.xml.parsers.ptests;
 
-import static jaxp.library.JAXPTestUtilities.failUnexpected;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
-
-import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-
+import jaxp.library.JAXPBaseTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
-import org.xml.sax.Parser;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.XMLReader;
 import org.xml.sax.ext.DeclHandler;
 import org.xml.sax.ext.LexicalHandler;
 
 /**
  * Class contains the test cases for SAXParser API
  */
-public class SAXParserTest02 {
-    final String DOM_NODE = "http://xml.org/sax/properties/dom-node";
-    final String XML_STRING = "http://xml.org/sax/properties/xml-string";
-    final String DECL_HANDLER = "http://xml.org/sax/properties/declaration-handler";
-    final String LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler";
+public class SAXParserTest02 extends JAXPBaseTest {
+    private static final String DOM_NODE = "http://xml.org/sax/properties/dom-node";
+    private static final String XML_STRING = "http://xml.org/sax/properties/xml-string";
+    private static final String DECL_HANDLER = "http://xml.org/sax/properties/declaration-handler";
+    private static final String LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler";
 
     /**
      * Provide SAXParser.
      *
-     * @throws SAXException
-     * @throws ParserConfigurationException
+     * @return a data provider contains a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws ParserConfigurationException in case of ServiceConfigurationError
+     * service configuration error or if the implementation is not available or
+     * cannot be instantiated.
      */
     @DataProvider(name = "parser-provider")
     public Object[][] getParser() throws ParserConfigurationException, SAXException {
         SAXParserFactory spf = SAXParserFactory.newInstance();
         SAXParser saxparser = spf.newSAXParser();
         return new Object[][] { { saxparser } };
     }
 
     /**
-     * Testcase to test the default functionality (No validation) of the parser.
+     * Test to test the default functionality (No validation) of the parser.
+     * 
+     * @param saxparser a SAXParser instance.
      */
     @Test(dataProvider = "parser-provider")
     public void testValidate01(SAXParser saxparser) {
-        try {
             assertFalse(saxparser.isValidating());
-        } catch (FactoryConfigurationError e) {
-            failUnexpected(e);
-        }
-
     }
 
     /**
-     * Testcase to test the functionality of setValidating and isvalidating
+     * Test to test the functionality of setValidating and isValidating
      * methods.
+     * 
+     * @throws ParserConfigurationException in case of ServiceConfigurationError
+     * service configuration error or if the implementation is not available or
+     * cannot be instantiated.
+     * @throws SAXException If any parse errors occur.
      */
     @Test
-    public void testValidate02() {
-        try {
+    public void testValidate02() throws ParserConfigurationException, SAXException {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setValidating(true);
             spf.newSAXParser();
             assertTrue(spf.isValidating());
-        } catch (FactoryConfigurationError | ParserConfigurationException | SAXException e) {
-            failUnexpected(e);
-        }
-
     }
 
     /**
-     * Test case to test isNamespaceAware() method. By default, namespaces are
+     * Test isNamespaceAware() method. By default, namespaces are
      * not supported.
+     * 
+     * @param saxparser a SAXParser instance.
      */
     @Test(dataProvider = "parser-provider")
     public void testNamespace01(SAXParser saxparser) {
-        try {
             assertFalse(saxparser.isNamespaceAware());
-        } catch (FactoryConfigurationError e) {
-            failUnexpected(e);
-        }
-
     }
 
     /**
      * Test case to test setnamespaceAware() method.
+     *
+     * @throws SAXException If any parse errors occur.
+     * @throws ParserConfigurationException in case of ServiceConfigurationError
+     * service configuration error or if the implementation is not available or
+     * cannot be instantiated.
      */
     @Test
-    public void testNamespace02() {
-        try {
+    public void testNamespace02() throws SAXException, ParserConfigurationException {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
             SAXParser saxparser = spf.newSAXParser();
             assertTrue(saxparser.isNamespaceAware());
-        } catch (FactoryConfigurationError | ParserConfigurationException | SAXException e) {
-            failUnexpected(e);
-        }
-
     }
 
     /**
      * Test case to test if the getParser() method returns instance of Parser.
+     * 
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
     @Test(dataProvider = "parser-provider")
-    public void testParser01(SAXParser saxparser) {
-        try {
-            Parser parser = saxparser.getParser();
-        } catch (FactoryConfigurationError | SAXException e) {
-            failUnexpected(e);
-        }
-
+    public void testParser01(SAXParser saxparser) throws SAXException {
+        saxparser.getParser();
     }
 
     /**
      * Test case to test if the getXMLReader() method returns instance of
      * XMLReader.
+     * 
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
     @Test(dataProvider = "parser-provider")
-    public void testXmlReader01(SAXParser saxparser) {
-        try {
-            XMLReader xmlReader = saxparser.getXMLReader();
-        } catch (FactoryConfigurationError | SAXException e) {
-            failUnexpected(e);
-        }
+    public void testXmlReader01(SAXParser saxparser) throws SAXException {
+        saxparser.getXMLReader();
     }
 
     /**
      * Test whether the xml-string property is not supported.
      *
-     * @throws SAXNotSupportedException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
-    @Test(expectedExceptions = SAXNotSupportedException.class, dataProvider = "parser-provider")
-    public void testProperty01(SAXParser saxparser) throws SAXNotSupportedException {
-        try {
-            Object object = saxparser.getProperty(XML_STRING);
-        } catch (SAXNotRecognizedException e) {
-            failUnexpected(e);
-        }
+    @Test(expectedExceptions = SAXNotSupportedException.class, 
+            dataProvider = "parser-provider")
+    public void testProperty01(SAXParser saxparser) throws SAXException {
+        saxparser.getProperty(XML_STRING);
     }
 
     /**
      * Test whether the dom-node property is not supported.
      *
-     * @throws SAXNotSupportedException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
-    @Test(expectedExceptions = SAXNotSupportedException.class, dataProvider = "parser-provider")
-    public void testProperty02(SAXParser saxparser) throws SAXNotSupportedException {
-        try {
-            Object object = saxparser.getProperty(DOM_NODE);
-        } catch (SAXNotRecognizedException e) {
-            failUnexpected(e);
-        }
+    @Test(expectedExceptions = SAXNotSupportedException.class,
+            dataProvider = "parser-provider")
+    public void testProperty02(SAXParser saxparser) throws SAXException {
+        saxparser.getProperty(DOM_NODE);
     }
 
     /**
      * Test the default lexical-handler not exists.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
     @Test(dataProvider = "parser-provider")
-    public void testProperty03(SAXParser saxparser) {
-        try {
+    public void testProperty03(SAXParser saxparser) throws SAXException {
             assertNull(saxparser.getProperty(LEXICAL_HANDLER));
-        } catch (SAXException e) {
-            failUnexpected(e);
-        }
-
     }
 
     /**
      * Test the default declaration-handler not exists.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
     @Test(dataProvider = "parser-provider")
-    public void testProperty04(SAXParser saxparser) {
-
-        try {
+    public void testProperty04(SAXParser saxparser) throws SAXException {
             assertNull(saxparser.getProperty(DECL_HANDLER));
-        } catch (SAXException e) {
-            failUnexpected(e);
-        }
     }
 
     /**
      * Test to set and get the lexical-handler.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
     @Test(dataProvider = "parser-provider")
-    public void testProperty05(SAXParser saxparser) {
-        try {
+    public void testProperty05(SAXParser saxparser) throws SAXException {
             MyLexicalHandler myLexicalHandler = new MyLexicalHandler();
             saxparser.setProperty(LEXICAL_HANDLER, myLexicalHandler);
-            Object object = saxparser.getProperty(LEXICAL_HANDLER);
-            assertTrue(object instanceof LexicalHandler);
-        } catch (SAXException e) {
-            failUnexpected(e);
-        }
+        assertTrue(saxparser.getProperty(LEXICAL_HANDLER) instanceof LexicalHandler);
     }
 
     /**
      * Test to set and get the declaration-handler.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
      */
     @Test(dataProvider = "parser-provider")
-    public void testProperty06(SAXParser saxparser) {
-        try {
+    public void testProperty06(SAXParser saxparser) throws SAXException {
             MyDeclHandler myDeclHandler = new MyDeclHandler();
             saxparser.setProperty(DECL_HANDLER, myDeclHandler);
-            Object object = saxparser.getProperty(DECL_HANDLER);
-            assertTrue(object instanceof DeclHandler);
-        } catch (SAXException e) {
-            failUnexpected(e);
-        }
-
+        assertTrue(saxparser.getProperty(DECL_HANDLER) instanceof DeclHandler);
     }
 
     /**
-     * Customized LexicalHandler used for test.
+     * Customized LexicalHandler used for test. An empty implementation for 
+     * LexicalHandler.
      */
     private class MyLexicalHandler implements LexicalHandler {
 
+        @Override
         public void comment(char[] ch, int start, int length) {
         }
 
+        @Override
         public void endCDATA() {
         }
 
+        @Override
         public void endDTD() {
         }
 
+        @Override
         public void endEntity(String name) {
         }
 
+        @Override
         public void startCDATA() {
         }
 
+        @Override
         public void startDTD(String name, String publicId, String systemId) {
         }
 
+        @Override
         public void startEntity(String name) {
         }
     }
 
     /**
-     * Customized DeclHandler used for test.
+     * Customized DeclHandler used for test. An empty implementation for 
+     * DeclHandler. 
      */
     private class MyDeclHandler implements DeclHandler {
 
+        @Override
         public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) {
         }
 
+        @Override
         public void elementDecl(String name, String model) {
         }
 
+        @Override
         public void externalEntityDecl(String name, String publicId, String systemId) {
         }
 
+        @Override
         public void internalEntityDecl(String name, String value) {
         }
     }
 }
< prev index next >