Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 94967 invoked from network); 5 Mar 2007 08:15:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Mar 2007 08:15:30 -0000 Received: (qmail 80680 invoked by uid 500); 5 Mar 2007 08:15:38 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 80657 invoked by uid 500); 5 Mar 2007 08:15:38 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 80648 invoked by uid 99); 5 Mar 2007 08:15:38 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2007 00:15:38 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2007 00:15:29 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id DC8FE1A981A; Mon, 5 Mar 2007 00:15:08 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r514598 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/ContentHandler.java test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java Date: Mon, 05 Mar 2007 08:15:08 -0000 To: commits@harmony.apache.org From: liangyx@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070305081508.DC8FE1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: liangyx Date: Mon Mar 5 00:15:07 2007 New Revision: 514598 URL: http://svn.apache.org/viewvc?view=rev&rev=514598 Log: We should check whether the content object is one of the types specified, not content.getClass() Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java (with props) Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java?view=diff&rev=514598&r1=514597&r2=514598 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java Mon Mar 5 00:15:07 2007 @@ -63,9 +63,8 @@ public Object getContent(URLConnection uConn, Class[] types) throws IOException { Object content = getContent(uConn); - Class cl = content.getClass(); for (int i = 0; i < types.length; i++) { - if (types[i].isInstance(cl)) { + if (types[i].isInstance(content)) { return content; } } Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java?view=auto&rev=514598 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java (added) +++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java Mon Mar 5 00:15:07 2007 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.harmony.luni.tests.java.net; + +import java.io.IOException; +import java.net.ContentHandler; +import java.net.URL; +import java.net.URLConnection; + +import junit.framework.TestCase; + +public class ContentHandlerTest extends TestCase { + + /** + * @tests 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); + } +} + +class ContentHandlerImpl extends ContentHandler { + + private Object content; + + @Override + public Object getContent(URLConnection uConn) throws IOException { + return content; + } + + public void setContent(Object content) { + this.content = content; + } +} + +class Foo { + public String getFoo() { + return "Foo"; + } +} + +class FooSub extends Foo { + public String getFoo() { + return "FooSub"; + } +} Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native