You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2015/11/11 15:40:21 UTC
svn commit: r1713854 - in
/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections:
TestFactoryUtils.java functors/TestPrototypeFactory.java
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;
+ }
+ }
+
}