diff options
Diffstat (limited to 'harmony-tests/src/test/java/org/apache/harmony/tests/org/xml/sax/helpers/ParserFactoryTest.java')
-rw-r--r-- | harmony-tests/src/test/java/org/apache/harmony/tests/org/xml/sax/helpers/ParserFactoryTest.java | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/org/xml/sax/helpers/ParserFactoryTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/org/xml/sax/helpers/ParserFactoryTest.java new file mode 100644 index 0000000..b59ce50 --- /dev/null +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/org/xml/sax/helpers/ParserFactoryTest.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.api.org.xml.sax.helpers; + +import junit.framework.TestCase; + +import org.xml.sax.helpers.ParserFactory; + +@SuppressWarnings("deprecation") +public class ParserFactoryTest extends TestCase { + + @Override protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testMakeParser() throws ClassNotFoundException, + IllegalAccessException, InstantiationException { + + System.clearProperty("org.xml.sax.parser"); + + // Property not set at all + try { + ParserFactory.makeParser(); + fail("expected NullPointerException was not thrown"); + } catch (NullPointerException e) { + // Expected + } + + // Unknown class + System.setProperty("org.xml.sax.parser", "foo.bar.SAXParser"); + + try { + ParserFactory.makeParser(); + fail("expected ClassNotFoundException was not thrown"); + } catch (ClassNotFoundException e) { + // Expected + } + + // Non-accessible class + System.setProperty("org.xml.sax.parser", + "tests.api.org.xml.sax.support.NoAccessParser"); + + try { + ParserFactory.makeParser(); + fail("expected IllegalAccessException was not thrown"); + } catch (IllegalAccessException e) { + // Expected + } + + // Non-instantiable class + System.setProperty("org.xml.sax.parser", + "tests.api.org.xml.sax.support.NoInstanceParser"); + + try { + ParserFactory.makeParser(); + fail("expected InstantiationException was not thrown"); + } catch (InstantiationException e) { + // Expected + } + + // Non-Parser class + System.setProperty("org.xml.sax.parser", + "tests.api.org.xml.sax.support.NoSubclassParser"); + + try { + ParserFactory.makeParser(); + fail("expected ClassCastException was not thrown"); + } catch (ClassCastException e) { + // Expected + } + + // Good one, finally + System.setProperty("org.xml.sax.parser", + "tests.api.org.xml.sax.support.DoNothingParser"); + + ParserFactory.makeParser(); + + } + + public void testMakeParserString() throws ClassNotFoundException, + IllegalAccessException, InstantiationException { + // No class + try { + ParserFactory.makeParser(null); + fail("expected NullPointerException was not thrown"); + } catch (NullPointerException e) { + // Expected + } + + // Unknown class + try { + ParserFactory.makeParser("foo.bar.SAXParser"); + fail("expected ClassNotFoundException was not thrown"); + } catch (ClassNotFoundException e) { + // Expected + } + + // Non-accessible class + try { + ParserFactory.makeParser( + "tests.api.org.xml.sax.support.NoAccessParser"); + fail("expected IllegalAccessException was not thrown"); + } catch (IllegalAccessException e) { + // Expected + } + + // Non-instantiable class + try { + ParserFactory.makeParser( + "tests.api.org.xml.sax.support.NoInstanceParser"); + fail("expected InstantiationException was not thrown"); + } catch (InstantiationException e) { + // Expected + } + + // Non-Parser class + try { + ParserFactory.makeParser( + "tests.api.org.xml.sax.support.NoSubclassParser"); + fail("expected ClassCastException was not thrown"); + } catch (ClassCastException e) { + // Expected + } + + // Good one, finally + ParserFactory.makeParser( + "tests.api.org.xml.sax.support.DoNothingParser"); + + } + +} |