Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D81E188CC for ; Wed, 11 Nov 2015 14:40:24 +0000 (UTC) Received: (qmail 716 invoked by uid 500); 11 Nov 2015 14:40:24 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 619 invoked by uid 500); 11 Nov 2015 14:40:23 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 610 invoked by uid 99); 11 Nov 2015 14:40:23 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Nov 2015 14:40:23 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 6FC93C3C3E for ; Wed, 11 Nov 2015 14:40:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.457 X-Spam-Level: * X-Spam-Status: No, score=1.457 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.343] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id PsjdNmOlt4mc for ; Wed, 11 Nov 2015 14:40:22 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 680D923056 for ; Wed, 11 Nov 2015 14:40:22 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id EB8F7E0044 for ; Wed, 11 Nov 2015 14:40:21 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id C97873A0798 for ; Wed, 11 Nov 2015 14:40:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1713854 - in /commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections: TestFactoryUtils.java functors/TestPrototypeFactory.java Date: Wed, 11 Nov 2015 14:40:21 -0000 To: commits@commons.apache.org From: tn@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151111144021.C97873A0798@svn01-us-west.apache.org> Author: tn Date: Wed Nov 11 14:40:21 2015 New Revision: 1713854 URL: http://svn.apache.org/viewvc?rev=1713854&view=rev Log: Move PrototypeFactory tests to new TestPrototypeFactory test. Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/TestFactoryUtils.java commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/functors/TestPrototypeFactory.java Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/TestFactoryUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/TestFactoryUtils.java?rev=1713854&r1=1713853&r2=1713854&view=diff ============================================================================== --- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/TestFactoryUtils.java (original) +++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/TestFactoryUtils.java Wed Nov 11 14:40:21 2015 @@ -129,68 +129,6 @@ public class TestFactoryUtils extends ju assertSame(ConstantFactory.NULL_INSTANCE, FactoryUtils.prototypeFactory(null)); } - public void testPrototypeFactoryPublicCloneMethod() throws Exception { - Date proto = new Date(); - Factory factory = FactoryUtils.prototypeFactory(proto); - assertNotNull(factory); - Object created = factory.create(); - assertTrue(proto != created); - assertEquals(proto, created); - - // check serialisation works - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(buffer); - out.writeObject(factory); - out.close(); - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); - Object dest = in.readObject(); - in.close(); - } - - public void testPrototypeFactoryPublicCopyConstructor() throws Exception { - Mock1 proto = new Mock1(6); - Factory factory = FactoryUtils.prototypeFactory(proto); - assertNotNull(factory); - Object created = factory.create(); - assertTrue(proto != created); - assertEquals(proto, created); - - // check serialisation works - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(buffer); - try { - out.writeObject(factory); - } catch (NotSerializableException ex) { - out.close(); - } - factory = FactoryUtils.prototypeFactory(new Mock2("S")); - buffer = new ByteArrayOutputStream(); - out = new ObjectOutputStream(buffer); - out.writeObject(factory); - out.close(); - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); - Object dest = in.readObject(); - in.close(); - } - - public void testPrototypeFactoryPublicSerialization() throws Exception { - Integer proto = new Integer(9); - Factory factory = FactoryUtils.prototypeFactory(proto); - assertNotNull(factory); - Object created = factory.create(); - assertTrue(proto != created); - assertEquals(proto, created); - - // check serialisation works - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(buffer); - out.writeObject(factory); - out.close(); - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); - Object dest = in.readObject(); - in.close(); - } - public void testPrototypeFactoryPublicSerializationError() { Mock2 proto = new Mock2(new Object()); Factory factory = FactoryUtils.prototypeFactory(proto); Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/functors/TestPrototypeFactory.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/functors/TestPrototypeFactory.java?rev=1713854&r1=1713853&r2=1713854&view=diff ============================================================================== --- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/functors/TestPrototypeFactory.java (original) +++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/functors/TestPrototypeFactory.java Wed Nov 11 14:40:21 2015 @@ -16,9 +16,17 @@ */ package org.apache.commons.collections.functors; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.NotSerializableException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.ArrayList; +import java.util.Date; import org.apache.commons.collections.Factory; +import org.apache.commons.collections.FactoryUtils; import junit.framework.Test; import junit.framework.TestSuite; @@ -46,4 +54,118 @@ public class TestPrototypeFactory extend return Factory.class; } + // ------------------------------------------------------------------------ + + public void testPrototypeFactoryPublicCloneMethod() throws Exception { + Date proto = new Date(); + Factory factory = PrototypeFactory.getInstance(proto); + assertNotNull(factory); + Object created = factory.create(); + assertTrue(proto != created); + assertEquals(proto, created); + + // check serialisation works - if enabled + System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "true"); + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(buffer); + out.writeObject(factory); + out.close(); + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); + Object dest = in.readObject(); + in.close(); + } finally { + System.clearProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY); + } + } + + public void testPrototypeFactoryPublicCopyConstructor() throws Exception { + Mock1 proto = new Mock1(6); + Factory factory = PrototypeFactory.getInstance(proto); + assertNotNull(factory); + Object created = factory.create(); + assertTrue(proto != created); + assertEquals(proto, created); + + // check serialisation works - if enabled + System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "true"); + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(buffer); + try { + out.writeObject(factory); + } catch (NotSerializableException ex) { + out.close(); + } + factory = FactoryUtils.prototypeFactory(new Mock2("S")); + buffer = new ByteArrayOutputStream(); + out = new ObjectOutputStream(buffer); + out.writeObject(factory); + out.close(); + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); + Object dest = in.readObject(); + in.close(); + } finally { + System.clearProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY); + } + } + + public void testPrototypeFactoryPublicSerialization() throws Exception { + Integer proto = new Integer(9); + Factory factory = FactoryUtils.prototypeFactory(proto); + assertNotNull(factory); + Object created = factory.create(); + assertTrue(proto != created); + assertEquals(proto, created); + + // check serialisation works - if enabled + System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "true"); + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(buffer); + out.writeObject(factory); + out.close(); + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); + Object dest = in.readObject(); + in.close(); + } finally { + System.clearProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY); + } + } + + // ------------------------------------------------------------------------ + + private static class Mock1 { + private final int iVal; + public Mock1(int val) { + iVal = val; + } + public Mock1(Mock1 mock) { + iVal = mock.iVal; + } + public boolean equals(Object obj) { + if (obj instanceof Mock1) { + if (iVal == ((Mock1) obj).iVal) { + return true; + } + } + return false; + } + } + + private static class Mock2 implements Serializable { + private final Object iVal; + public Mock2(Object val) { + iVal = val; + } + public boolean equals(Object obj) { + if (obj instanceof Mock2) { + if (iVal == ((Mock2) obj).iVal) { + return true; + } + } + return false; + } + } + }