java: Move contents of DeepCopyTest to TestStruct; delete old version
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@928157 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/build.xml b/lib/java/build.xml
index 442caed..0ca3200 100644
--- a/lib/java/build.xml
+++ b/lib/java/build.xml
@@ -195,8 +195,6 @@
classpathref="test.classpath" failonerror="true" />
<java classname="org.apache.thrift.test.ToStringTest"
classpathref="test.classpath" failonerror="true" />
- <java classname="org.apache.thrift.test.DeepCopyTest"
- classpathref="test.classpath" failonerror="true" />
<java classname="org.apache.thrift.test.CompareTest"
classpathref="test.classpath" failonerror="true" />
<java classname="org.apache.thrift.test.MetaDataTest"
diff --git a/lib/java/test/org/apache/thrift/TestStruct.java b/lib/java/test/org/apache/thrift/TestStruct.java
index 9ee305f..bcce32e 100644
--- a/lib/java/test/org/apache/thrift/TestStruct.java
+++ b/lib/java/test/org/apache/thrift/TestStruct.java
@@ -4,14 +4,12 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.Map;
import junit.framework.TestCase;
import org.apache.thrift.protocol.TBinaryProtocol;
import thrift.test.HolyMoley;
-import thrift.test.JavaTestHelper;
import thrift.test.Nesting;
import thrift.test.OneOfEach;
@@ -82,4 +80,29 @@
assertEquals(hm, hm2);
assertEquals(hm.hashCode(), hm2.hashCode());
}
+
+ public void testDeepCopy() throws Exception {
+ TSerializer binarySerializer = new TSerializer(new TBinaryProtocol.Factory());
+ TDeserializer binaryDeserializer = new TDeserializer(new TBinaryProtocol.Factory());
+
+ HolyMoley hm = Fixtures.holyMoley;
+
+ byte[] binaryCopy = binarySerializer.serialize(hm);
+ HolyMoley hmCopy = new HolyMoley();
+ binaryDeserializer.deserialize(hmCopy, binaryCopy);
+ HolyMoley hmCopy2 = new HolyMoley(hm);
+
+ assertEquals(hm, hmCopy);
+ assertEquals(hmCopy, hmCopy2);
+
+ // change binary value in original object
+ hm.big.get(0).base64[0]++;
+ // make sure the change didn't propagate to the copied object
+ assertFalse(hm.equals(hmCopy2));
+ hm.big.get(0).base64[0]--; // undo change
+
+ hmCopy2.bonks.get("two").get(1).message = "What else?";
+
+ assertFalse(hm.equals(hmCopy2));
+ }
}
diff --git a/lib/java/test/org/apache/thrift/test/DeepCopyTest.java b/lib/java/test/org/apache/thrift/test/DeepCopyTest.java
deleted file mode 100644
index abf3067..0000000
--- a/lib/java/test/org/apache/thrift/test/DeepCopyTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.thrift.test;
-
-import org.apache.thrift.Fixtures;
-import org.apache.thrift.TDeserializer;
-import org.apache.thrift.TSerializer;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import thrift.test.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-
-public class DeepCopyTest {
- public static void main(String[] args) throws Exception {
- TSerializer binarySerializer = new TSerializer(new TBinaryProtocol.Factory());
- TDeserializer binaryDeserializer = new TDeserializer(new TBinaryProtocol.Factory());
-
- HolyMoley hm = Fixtures.holyMoley;
-
- byte[] binaryCopy = binarySerializer.serialize(hm);
- HolyMoley hmCopy = new HolyMoley();
- binaryDeserializer.deserialize(hmCopy, binaryCopy);
- HolyMoley hmCopy2 = new HolyMoley(hm);
-
- if (!hm.equals(hmCopy))
- throw new RuntimeException("copy constructor modified the original object!");
- if (!hmCopy.equals(hmCopy2))
- throw new RuntimeException("copy constructor generated incorrect copy");
-
- hm.big.get(0).base64[0]++; // change binary value in original object
- if (hm.equals(hmCopy2)) // make sure the change didn't propagate to the copied object
- throw new RuntimeException("Binary field not copied correctly!");
- hm.big.get(0).base64[0]--; // undo change
-
- hmCopy2.bonks.get("two").get(1).message = "What else?";
-
- if (hm.equals(hmCopy2))
- throw new RuntimeException("A deep copy was not done!");
-
- }
-}