use of java.net.ContentHandler in project robovm by robovm.
the class ContentHandlerFactoryTest method test_createContentHandler.
@SideEffect("This test affects tests that are run after this one." + " The reason are side effects due to caching in URLConnection." + " Maybe this test needs to be run in isolation.")
public void test_createContentHandler() throws IOException {
TestContentHandlerFactory factory = new TestContentHandlerFactory();
if (isTestable) {
assertFalse(isCreateContentHandlerCalled);
URL url = new URL("http://" + Support_Configuration.SpecialInetTestAddress);
URLConnection.setContentHandlerFactory(factory);
URLConnection con = url.openConnection();
try {
con.getContent();
assertTrue(isCreateContentHandlerCalled);
assertTrue(isGetContentCalled);
} catch (Exception e) {
throw new RuntimeException(e);
}
isGetContentCalled = false;
try {
con.getContent(new Class[] {});
assertTrue(isGetContentCalled);
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
con.setContentHandlerFactory(factory);
fail("java.lang.Error was not thrown.");
} catch (java.lang.Error e) {
//expected
}
try {
con.setContentHandlerFactory(null);
fail("java.lang.Error was not thrown.");
} catch (java.lang.Error e) {
//expected
}
} else {
ContentHandler ch = factory.createContentHandler("text/plain");
URL url;
try {
url = new URL("http://" + Support_Configuration.SpecialInetTestAddress);
assertNotNull(ch.getContent(url.openConnection()));
} catch (MalformedURLException e) {
fail("MalformedURLException was thrown: " + e.getMessage());
} catch (IOException e) {
fail("IOException was thrown.");
}
}
}
use of java.net.ContentHandler in project robovm by robovm.
the class FooSub method test_getContent.
/**
* java.net.ContentHandler#getContent(java.net.URLConnection,
* java.lang.Class[])
*/
public void test_getContent() throws IOException {
URLConnection conn = new URL("http://www.apache.org").openConnection();
Class[] classes = { Foo.class, String.class };
ContentHandler handler = new ContentHandlerImpl();
((ContentHandlerImpl) handler).setContent(new Foo());
Object content = handler.getContent(conn, classes);
assertEquals("Foo", ((Foo) content).getFoo());
((ContentHandlerImpl) handler).setContent(new FooSub());
content = handler.getContent(conn, classes);
assertEquals("FooSub", ((Foo) content).getFoo());
Class[] classes2 = { FooSub.class, String.class };
((ContentHandlerImpl) handler).setContent(new Foo());
content = handler.getContent(conn, classes2);
assertNull(content);
}
Aggregations