|
|
@@ -7,6 +7,7 @@
|
|
|
package net.ranides.assira.generic;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.Serializable;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
@@ -22,7 +23,7 @@ public class SerializationUtilsTest {
|
|
|
|
|
|
@Test
|
|
|
public void testCopy() throws IOException {
|
|
|
- List<Integer> a = new ArrayList<Integer>(Arrays.asList(1,2,3,4));
|
|
|
+ List<Integer> a = new ArrayList<>(Arrays.asList(1,2,3,4));
|
|
|
List<Integer> b = SerializationUtils.copy(a);
|
|
|
|
|
|
assertEquals(a,b);
|
|
|
@@ -31,12 +32,12 @@ public class SerializationUtilsTest {
|
|
|
|
|
|
@Test
|
|
|
public void testSizeOf() throws IOException {
|
|
|
- List<Integer> a1 = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8));
|
|
|
- List<Integer> a2 = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16));
|
|
|
- List<Float> b1 = new ArrayList<Float>(Arrays.asList(1.f, 2.f, 3.f, 4.f));
|
|
|
- List<Float> b2 = new ArrayList<Float>(Arrays.asList(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f));
|
|
|
- List<String> c1 = new ArrayList<String>(Arrays.asList("T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8"));
|
|
|
- List<String> c2 = new ArrayList<String>(Arrays.asList(
|
|
|
+ List<Integer> a1 = new ArrayList<>(Arrays.asList(1,2,3,4,5,6,7,8));
|
|
|
+ List<Integer> a2 = new ArrayList<>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16));
|
|
|
+ List<Float> b1 = new ArrayList<>(Arrays.asList(1.f, 2.f, 3.f, 4.f));
|
|
|
+ List<Float> b2 = new ArrayList<>(Arrays.asList(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f));
|
|
|
+ List<String> c1 = new ArrayList<>(Arrays.asList("T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8"));
|
|
|
+ List<String> c2 = new ArrayList<>(Arrays.asList(
|
|
|
"T1....................................1",
|
|
|
"T2....................................2",
|
|
|
"T3....................................3",
|
|
|
@@ -71,5 +72,69 @@ public class SerializationUtilsTest {
|
|
|
assertTrue( ic1.size() < ic2.size());
|
|
|
assertTrue( ic1.element()< ic2.element());
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testProxy() throws IOException {
|
|
|
+ MyValue0 a = SerializationUtils.copy(new MyValue0("x", "22"));
|
|
|
+ MyValue0 b = SerializationUtils.copy(new MyValue1("x", "22"));
|
|
|
+ MyValue0 c = SerializationUtils.copy(new MyValue2("x", "22"));
|
|
|
+ MyValue0 d = SerializationUtils.copy(new MyValue3("x", "22"));
|
|
|
+
|
|
|
+ assertEquals("null : null", a.toString());
|
|
|
+ assertEquals("x : 22", b.toString());
|
|
|
+ assertEquals("x! : 22??", c.toString());
|
|
|
+ assertEquals("null : null", d.toString());
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("PMD")
|
|
|
+ private static class MyValue0 implements Serializable {
|
|
|
+
|
|
|
+ transient final String a;
|
|
|
+ transient final String b;
|
|
|
+
|
|
|
+ public MyValue0(String a, String b) {
|
|
|
+ this.a = a;
|
|
|
+ this.b = b;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return a + " : " + b;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class MyValue1 extends MyValue0 {
|
|
|
+
|
|
|
+ public MyValue1(String a, String b) {
|
|
|
+ super(a, b);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object writeReplace() {
|
|
|
+ return SerializationUtils.proxy(this, a, b);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class MyValue2 extends MyValue1 {
|
|
|
+
|
|
|
+ public MyValue2(String a, String b) {
|
|
|
+ super(a, b+"?");
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object writeReplace() {
|
|
|
+ return SerializationUtils.proxy(this, a+"!", b);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class MyValue3 extends MyValue1 {
|
|
|
+
|
|
|
+ public MyValue3(String a, String b) {
|
|
|
+ super(a, b+"?");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|