summaryrefslogtreecommitdiffstats
path: root/xml
diff options
context:
space:
mode:
authorUrs Grob <>2009-04-14 10:11:29 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-14 10:11:29 -0700
commit834e5096a6bd02a677c2346e6aa420af37b70523 (patch)
tree721298d1ab95fe6ea04b00f490e6319a31a914c4 /xml
parent73c376c583e571d1f208aa02a163bf8490c355bc (diff)
downloadlibcore-834e5096a6bd02a677c2346e6aa420af37b70523.zip
libcore-834e5096a6bd02a677c2346e6aa420af37b70523.tar.gz
libcore-834e5096a6bd02a677c2346e6aa420af37b70523.tar.bz2
AI 146132: Fixes from the review of 'Bringing XML down to one broken test.'
BUG=1285921 Automated import of CL 146132
Diffstat (limited to 'xml')
-rw-r--r--xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java39
-rw-r--r--xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java20
2 files changed, 33 insertions, 26 deletions
diff --git a/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java b/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
index 793139d..c515d20 100644
--- a/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
+++ b/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
@@ -19,6 +19,7 @@ package tests.api.javax.xml.parsers;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -279,16 +280,7 @@ public class DocumentBuilderTest extends TestCase {
)
@KnownFailure("d.getChildNodes returns an unexpected/strange #Text node")
public void test_parseLjava_io_File() throws IOException {
- File f = File.createTempFile("simple", ".xml");
- f.deleteOnExit();
- InputStream xml = getClass().getResourceAsStream("/simple.xml");
- FileOutputStream out = new FileOutputStream(f);
- while (xml.available() > 0) {
- out.write(xml.read());
- }
- out.flush();
- out.close();
- xml.close();
+ File f = resourceToTmpFile("/simple.xml");
// case 1: Trivial use.
try {
@@ -330,16 +322,7 @@ public class DocumentBuilderTest extends TestCase {
}
// case 4: Try to parse incorrect xml file
- f = File.createTempFile("wrong", ".xml");
- f.deleteOnExit();
- xml = getClass().getResourceAsStream("/wrong.xml");
- out = new FileOutputStream(f);
- while (xml.available() > 0) {
- out.write(xml.read());
- }
- out.flush();
- out.close();
- xml.close();
+ f = resourceToTmpFile("/wrong.xml");
try {
db.parse(f);
fail("Expected SAXException was not thrown");
@@ -350,6 +333,22 @@ public class DocumentBuilderTest extends TestCase {
}
}
+ private File resourceToTmpFile(String path) throws IOException,
+ FileNotFoundException {
+ File f = File.createTempFile("out", ".xml");
+ f.deleteOnExit();
+ FileOutputStream out = new FileOutputStream(f);
+
+ InputStream xml = getClass().getResourceAsStream(path);
+ while (xml.available() > 0) {
+ out.write(xml.read());
+ }
+ out.flush();
+ out.close();
+ xml.close();
+ return f;
+ }
+
/**
* @tests javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream)
* Case 1: Try to parse correct xml document.
diff --git a/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java b/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java
index 5ac87d5..1ef0ee4 100644
--- a/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java
+++ b/xml/src/test/java/tests/api/org/xml/sax/helpers/ParserFactoryTest.java
@@ -34,12 +34,12 @@ public class ParserFactoryTest extends TestCase {
args = { },
notes = "Checks everything except META-INF case"
)
- public void testMakeParser() throws NullPointerException,
- ClassCastException, ClassNotFoundException, InstantiationException,
- IllegalAccessException {
+ public void testMakeParser() throws ClassNotFoundException,
+ IllegalAccessException, InstantiationException {
// Property not set at all
try {
ParserFactory.makeParser();
+ fail("expected NullPointerException was not thrown");
} catch (NullPointerException e) {
// Expected
}
@@ -49,6 +49,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser();
+ fail("expected ClassNotFoundException was not thrown");
} catch (ClassNotFoundException e) {
// Expected
}
@@ -59,6 +60,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser();
+ fail("expected IllegalAccessException was not thrown");
} catch (IllegalAccessException e) {
// Expected
}
@@ -69,6 +71,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser();
+ fail("expected InstantiationException was not thrown");
} catch (InstantiationException e) {
// Expected
}
@@ -79,6 +82,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser();
+ fail("expected ClassCastException was not thrown");
} catch (ClassCastException e) {
// Expected
}
@@ -96,12 +100,12 @@ public class ParserFactoryTest extends TestCase {
method = "makeParser",
args = { String.class }
)
- public void testMakeParserString() throws ClassCastException,
- ClassNotFoundException, IllegalAccessException,
- InstantiationException {
+ public void testMakeParserString() throws ClassNotFoundException,
+ IllegalAccessException, InstantiationException {
// No class
try {
ParserFactory.makeParser(null);
+ fail("expected NullPointerException was not thrown");
} catch (NullPointerException e) {
// Expected
}
@@ -109,6 +113,7 @@ public class ParserFactoryTest extends TestCase {
// Unknown class
try {
ParserFactory.makeParser("foo.bar.SAXParser");
+ fail("expected ClassNotFoundException was not thrown");
} catch (ClassNotFoundException e) {
// Expected
}
@@ -117,6 +122,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser(
"tests.api.org.xml.sax.support.NoAccessParser");
+ fail("expected IllegalAccessException was not thrown");
} catch (IllegalAccessException e) {
// Expected
}
@@ -125,6 +131,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser(
"tests.api.org.xml.sax.support.NoInstanceParser");
+ fail("expected InstantiationException was not thrown");
} catch (InstantiationException e) {
// Expected
}
@@ -133,6 +140,7 @@ public class ParserFactoryTest extends TestCase {
try {
ParserFactory.makeParser(
"tests.api.org.xml.sax.support.NoSubclassParser");
+ fail("expected ClassCastException was not thrown");
} catch (ClassCastException e) {
// Expected
}