use of org.apache.harmony.tests.org.xml.sax.support.MethodLogger in project j2objc by google.
the class DocumentBuilderTest method testSetErrorHandler.
public void testSetErrorHandler() {
// Ordinary case
InputStream source = new ByteArrayInputStream("</a>".getBytes());
MethodLogger logger = new MethodLogger();
ErrorHandler handler = new MockHandler(logger);
try {
db = dbf.newDocumentBuilder();
db.setErrorHandler(handler);
db.parse(source);
} catch (SAXParseException e) {
// Expected, ErrorHandler does not mask exception
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
assertEquals("error", logger.getMethod());
assertTrue(logger.getArgs()[0] instanceof SAXParseException);
// null case
source = new ByteArrayInputStream("</a>".getBytes());
try {
db = dbf.newDocumentBuilder();
db.setErrorHandler(null);
db.parse(source);
} catch (SAXParseException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
}
use of org.apache.harmony.tests.org.xml.sax.support.MethodLogger in project j2objc by google.
the class DocumentBuilderTest method testReset.
public void testReset() {
// Make sure EntityResolver gets reset
InputStream source = new ByteArrayInputStream("<a>&foo;</a>".getBytes());
InputStream entity = new ByteArrayInputStream("bar".getBytes());
MockResolver resolver = new MockResolver();
resolver.addEntity("foo", "foo", new InputSource(entity));
Document d;
try {
db = dbf.newDocumentBuilder();
db.setEntityResolver(resolver);
db.reset();
d = db.parse(source);
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
Element root = (Element) d.getElementsByTagName("a").item(0);
assertEquals("foo", ((EntityReference) root.getFirstChild()).getNodeName());
// Make sure ErrorHandler gets reset
source = new ByteArrayInputStream("</a>".getBytes());
MethodLogger logger = new MethodLogger();
ErrorHandler handler = new MockHandler(logger);
try {
db = dbf.newDocumentBuilder();
db.setErrorHandler(handler);
db.reset();
d = db.parse(source);
} catch (SAXParseException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
assertEquals(0, logger.size());
}
Aggregations