summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-12-04 17:53:29 +0000
committerNarayan Kamath <narayan@google.com>2014-12-04 18:01:13 +0000
commit72c6ce7e114d45facd0a34be35831bb96f73442e (patch)
tree101e5d6d16d29e448690d5a7a76ebebcfe12b7d6
parent04704e37a20e6992e64583822b91d325d83aee48 (diff)
downloadlibcore-72c6ce7e114d45facd0a34be35831bb96f73442e.zip
libcore-72c6ce7e114d45facd0a34be35831bb96f73442e.tar.gz
libcore-72c6ce7e114d45facd0a34be35831bb96f73442e.tar.bz2
Delete ContentHandlerFactoryTest.
It uses reflection, has all sorts of weird stuff in it and isn't run as part of CTS because it has irreversible side effects (the last of these isn't the tests fault). There's no good reason to keep it, and it seems infeasible to write a half-decent test without adding lots of hidden api (which defeats the purpose of the test in the first place). bug: 18619181 (cherry picked from commit e9847f0ca58cec293b3a6298b7549cfabe6a30c9) Change-Id: Ia69c0011683eac90e4cca70a8f3f15fb82cece44
-rw-r--r--expectations/brokentests.txt7
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java145
2 files changed, 0 insertions, 152 deletions
diff --git a/expectations/brokentests.txt b/expectations/brokentests.txt
index 5cebb63..aa06985 100644
--- a/expectations/brokentests.txt
+++ b/expectations/brokentests.txt
@@ -142,13 +142,6 @@
]
},
{
- description: "This test affects tests that are run after this one due to caching in URLConnection.",
- result: EXEC_FAILED,
- names: [
- "org.apache.harmony.luni.tests.java.net.ContentHandlerFactoryTest#test_createContentHandler"
- ]
-},
-{
description: "Causes OutOfMemoryError to test finalization",
result: EXEC_FAILED,
names: [
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java
deleted file mode 100644
index f3d5518..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-package org.apache.harmony.luni.tests.java.net;
-
-import junit.framework.TestCase;
-
-import tests.support.Support_Configuration;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.net.ContentHandler;
-import java.net.ContentHandlerFactory;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-
-public class ContentHandlerFactoryTest extends TestCase {
-
- ContentHandlerFactory oldFactory = null;
- Field factoryField = null;
-
- boolean isTestable = false;
-
- boolean isGetContentCalled = false;
- boolean isCreateContentHandlerCalled = false;
-
- // 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.");
- }
- }
- }
-
- public void setUp() {
- Field [] fields = URLConnection.class.getDeclaredFields();
- int counter = 0;
- for (Field field : fields) {
- if (ContentHandlerFactory.class.equals(field.getType())) {
- counter++;
- factoryField = field;
- }
- }
-
- if(counter == 1) {
-
- isTestable = true;
-
- factoryField.setAccessible(true);
- try {
- oldFactory = (ContentHandlerFactory) factoryField.get(null);
- } catch (IllegalArgumentException e) {
- fail("IllegalArgumentException was thrown during setUp: "
- + e.getMessage());
- } catch (IllegalAccessException e) {
- fail("IllegalAccessException was thrown during setUp: "
- + e.getMessage());
- }
- }
- }
-
- public void tearDown() {
- if(isTestable) {
- try {
- factoryField.set(null, oldFactory);
- } catch (IllegalArgumentException e) {
- fail("IllegalArgumentException was thrown during tearDown: "
- + e.getMessage());
- } catch (IllegalAccessException e) {
- fail("IllegalAccessException was thrown during tearDown: "
- + e.getMessage());
- }
- }
- }
-
- public class TestContentHandler extends ContentHandler {
-
- public Object getContent(URLConnection u) {
- isGetContentCalled = true;
- return null;
- }
- }
-
- public class TestContentHandlerFactory implements ContentHandlerFactory {
-
- public ContentHandler createContentHandler(String mimetype) {
- isCreateContentHandlerCalled = true;
- return new TestContentHandler();
- }
- }
-}