From 4fb060d5213a3d3fe6988bbe725b82c8aed02f23 Mon Sep 17 00:00:00 2001 From: lo1nt Date: Wed, 20 Mar 2024 17:00:31 +0800 Subject: [PATCH] ut --- .../caucho/hessian/io/WriteReplaceTest.java | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/caucho/hessian/io/WriteReplaceTest.java b/src/test/java/com/caucho/hessian/io/WriteReplaceTest.java index b478f8f..c3fc862 100644 --- a/src/test/java/com/caucho/hessian/io/WriteReplaceTest.java +++ b/src/test/java/com/caucho/hessian/io/WriteReplaceTest.java @@ -70,6 +70,10 @@ public void TestWrappedWriteReplace() throws IOException { testObject.setName("testWR"); origin.setTestObject(testObject); + TestObjectWriteReplace wrObject = new TestObjectWriteReplace(); + wrObject.name = "testProxy"; + origin.setWrObject(wrObject); + os.reset(); Hessian2Output output = new Hessian2Output(os); @@ -86,28 +90,54 @@ public void TestWrappedWriteReplace() throws IOException { input.setSerializerFactory(factory); WrappedTestObject actual = (WrappedTestObject) input.readObject(); Assert.assertEquals(actual.testObject.name, origin.testObject.name); + Assert.assertEquals(actual.wrObject.name, origin.wrObject.name); } private static class WrappedTestObject implements Serializable { - private TestObject testObject; + private TestObject testObject; + private TestObjectWriteReplace wrObject; - /** - * Getter method for property testObject. - * - * @return property value of testObject - */ public TestObject getTestObject() { return testObject; } - /** - * Setter method for property testObject. - * - * @param testObject value to be assigned to property testObject - */ public void setTestObject(TestObject testObject) { this.testObject = testObject; } + + public TestObjectWriteReplace getWrObject() { + return wrObject; + } + + public void setWrObject(TestObjectWriteReplace wrObject) { + this.wrObject = wrObject; + } + } + + // write replace to TestObjectProxy + private static class TestObjectWriteReplace implements Serializable { + private static final long serialVersionUID = 462771763706189820L; + + String name; + + Object writeReplace() { + TestObjectProxy o = new TestObjectProxy(); + o.name = this.name; + return o; + } + } + + // read resolve back to TestObjectWriteReplace + private static class TestObjectProxy implements Serializable { + private static final long serialVersionUID = 462771763706189820L; + + String name; + + Object readResolve() { + TestObjectWriteReplace o = new TestObjectWriteReplace(); + o.name = this.name; + return o; + } } private static class TestObject implements Serializable {