Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 18746 invoked from network); 22 Aug 2005 00:54:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Aug 2005 00:54:34 -0000 Received: (qmail 6742 invoked by uid 500); 22 Aug 2005 00:54:31 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 6686 invoked by uid 500); 22 Aug 2005 00:54:31 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 6673 invoked by uid 500); 22 Aug 2005 00:54:31 -0000 Received: (qmail 6667 invoked by uid 99); 22 Aug 2005 00:54:31 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 21 Aug 2005 17:54:30 -0700 Received: (qmail 18733 invoked by uid 65534); 22 Aug 2005 00:54:30 -0000 Message-ID: <20050822005430.18732.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r234406 - /jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SerializationUtilsTest.java Date: Mon, 22 Aug 2005 00:54:30 -0000 To: commons-cvs@jakarta.apache.org From: stevencaswell@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: stevencaswell Date: Sun Aug 21 17:54:27 2005 New Revision: 234406 URL: http://svn.apache.org/viewcvs?rev=234406&view=rev Log: increase SerializationUtils test coverage as reported by clover Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SerializationUtilsTest.java Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SerializationUtilsTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SerializationUtilsTest.java?rev=234406&r1=234405&r2=234406&view=diff ============================================================================== --- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SerializationUtilsTest.java (original) +++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SerializationUtilsTest.java Sun Aug 21 17:54:27 2005 @@ -17,8 +17,12 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; +import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import java.util.HashMap; @@ -36,6 +40,10 @@ * @version $Id$ */ public class SerializationUtilsTest extends TestCase { + + static final String CLASS_NOT_FOUND_MESSAGE = "ClassNotFoundSerializationTest.readObject fake exception"; + protected static final String SERIALIZE_IO_EXCEPTION_MESSAGE = "Anonymous OutputStream I/O exception"; + private String iString; private Integer iInteger; private HashMap iMap; @@ -166,6 +174,22 @@ } fail(); } + + public void testSerializeIOException() throws Exception { + // forces an IOException when the ObjectOutputStream is created, to test not closing the stream + // in the finally block + OutputStream streamTest = new OutputStream() { + public void write(int arg0) throws IOException { + throw new IOException(SERIALIZE_IO_EXCEPTION_MESSAGE); + } + }; + try { + SerializationUtils.serialize(iMap, streamTest); + } + catch(SerializationException e) { + assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage()); + } + } //----------------------------------------------------------------------- @@ -219,6 +243,21 @@ fail(); } + public void testDeserializeStreamClassNotFound() throws Exception { + ByteArrayOutputStream streamReal = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(streamReal); + oos.writeObject(new ClassNotFoundSerializationTest()); + oos.flush(); + oos.close(); + + ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray()); + try { + Object test = SerializationUtils.deserialize(inTest); + } catch(SerializationException se) { + assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage()); + } + } + //----------------------------------------------------------------------- public void testSerializeBytes() throws Exception { @@ -344,3 +383,11 @@ } } + +class ClassNotFoundSerializationTest implements Serializable +{ + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + throw new ClassNotFoundException(SerializationUtilsTest.CLASS_NOT_FOUND_MESSAGE); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org