From 7719a05aaa344a3d00721f457c9c6d399f6de9d9 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Wed, 15 Oct 2014 13:24:04 +0100 Subject: [PATCH] added MyTestClassObjectGraph test --- .../chronicle/map/StatelessMapClientTest.java | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/openhft/chronicle/map/StatelessMapClientTest.java b/src/test/java/net/openhft/chronicle/map/StatelessMapClientTest.java index e03a2d14f..19f5c39a5 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessMapClientTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessMapClientTest.java @@ -8,7 +8,7 @@ import net.openhft.lang.model.constraints.NotNull; import org.junit.Assert; import org.junit.Test; -import java.io.Serializable; +import java.io.*; import java.nio.ByteBuffer; import java.util.Collections; @@ -27,6 +27,10 @@ public class StatelessMapClientTest extends TestCase { testReadValueWriteValue(new MyTestClass(3)); testReadValueWriteValue(new MyTestClassMarshallable(3)); + testReadValueWriteValue(new MyTestClassExternalizable(3)); + testReadValueWriteValue(new MyTestClassObjectGraph(3)); + + } public void testReadValueWriteValue(Object value) throws Exception { @@ -50,6 +54,45 @@ public class StatelessMapClientTest extends TestCase { } + public static class MyTestClassExternalizable implements Externalizable { + int a; + + public MyTestClassExternalizable() { + } + + + MyTestClassExternalizable(int a) { + this.a = a; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MyTestClassExternalizable that = (MyTestClassExternalizable) o; + + if (a != that.a) return false; + + return true; + } + + @Override + public int hashCode() { + return a; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.write(a); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + a = in.readInt(); + } + } + public static class MyTestClass implements Serializable { int a; @@ -85,6 +128,10 @@ public class StatelessMapClientTest extends TestCase { this.a = a; } + public void setA(int a) { + this.a = a; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -116,5 +163,36 @@ public class StatelessMapClientTest extends TestCase { } } + public static class MyTestClassObjectGraph implements Serializable { + + MyTestClassMarshallable delegate; + + public MyTestClassObjectGraph() { + + } + + MyTestClassObjectGraph(int a) { + delegate = new MyTestClassMarshallable(a); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MyTestClassObjectGraph that = (MyTestClassObjectGraph) o; + + if (delegate != null ? !delegate.equals(that.delegate) : that.delegate != null) + return false; + + return true; + } + + @Override + public int hashCode() { + return delegate != null ? delegate.hashCode() : 0; + } + } + } \ No newline at end of file