added MyTestClassObjectGraph test

This commit is contained in:
Rob Austin
2014-10-15 13:24:04 +01:00
parent 1fb48ade34
commit 7719a05aaa
@@ -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;
}
}
}