JSON object stream bug fixes
This commit is contained in:
parent
0f94a575a3
commit
2a51090813
3 changed files with 51 additions and 67 deletions
|
|
@ -36,7 +36,9 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class JSONSerializerTest{
|
||||
|
||||
|
|
@ -47,9 +49,9 @@ public class JSONSerializerTest{
|
|||
String data = writeObjectToJson(sourceObj);
|
||||
data = data.replace("\"", "'");
|
||||
|
||||
assertEquals(
|
||||
"{'str': 'abcd', '@class': 'zutil.test.JSONSerializerTest$TestClass', 'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': 42, '@object_id': 2}, 'obj2': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': 42, '@object_id': 3}, 'decimal': 1.1, '@object_id': 1}\n",
|
||||
data);
|
||||
assertThat(data, containsString("'str': 'abcd'"));
|
||||
assertThat(data, containsString("'value': 42"));
|
||||
assertThat(data, containsString("'decimal': 1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -68,9 +70,9 @@ public class JSONSerializerTest{
|
|||
String data = writeObjectToJson(sourceObj);
|
||||
data = data.replace("\"", "'");
|
||||
|
||||
assertEquals(
|
||||
"{'@class': 'zutil.test.JSONSerializerTest$TestClassObjClone', 'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': 42, '@object_id': 2}, 'obj2': {'@object_id': 2}, '@object_id': 1}\n",
|
||||
data);
|
||||
assertThat(data, containsString("'@class': 'zutil.test.JSONSerializerTest$TestClassObjClone'"));
|
||||
assertThat(data, containsString("'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', '@object_id': 2, 'value': 42}"));
|
||||
assertThat(data, containsString("'obj2': {'@object_id': 2}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -99,7 +101,6 @@ public class JSONSerializerTest{
|
|||
TestClassArray sourceObj = new TestClassArray().init();
|
||||
|
||||
TestClassArray targetObj = sendReceiveObject(sourceObj);
|
||||
|
||||
assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +109,6 @@ public class JSONSerializerTest{
|
|||
TestClassStringArray sourceObj = new TestClassStringArray().init();
|
||||
|
||||
TestClassStringArray targetObj = sendReceiveObject(sourceObj);
|
||||
|
||||
assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
|
||||
|
|
@ -130,12 +130,6 @@ public class JSONSerializerTest{
|
|||
public void testSerializerWithMapField() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClassMap sourceObj = new TestClassMap().init();
|
||||
|
||||
String data = writeObjectToJson(sourceObj, false);
|
||||
data = data.replace("\"", "'");
|
||||
assertEquals(
|
||||
"{'map': {'key2': 'value2', 'key1': 'value1'}}\n",
|
||||
data);
|
||||
|
||||
TestClassMap targetObj = sendReceiveObject(sourceObj);
|
||||
TestClassMap.assertEquals(sourceObj, targetObj);
|
||||
}
|
||||
|
|
@ -145,12 +139,6 @@ public class JSONSerializerTest{
|
|||
TestClassMap sourceObj = new TestClassMap().init();
|
||||
sourceObj.map.put("key1", null);
|
||||
|
||||
String data = writeObjectToJson(sourceObj, false);
|
||||
data = data.replace("\"", "'");
|
||||
assertEquals(
|
||||
"{'map': {'key2': 'value2', 'key1': null}}\n",
|
||||
data);
|
||||
|
||||
TestClassMap targetObj = sendReceiveObject(sourceObj);
|
||||
TestClassMap.assertEquals(sourceObj, targetObj);
|
||||
}
|
||||
|
|
@ -159,11 +147,9 @@ public class JSONSerializerTest{
|
|||
public void testSerializerWithListField() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClassList sourceObj = new TestClassList().init();
|
||||
|
||||
String data = writeObjectToJson(sourceObj, false);
|
||||
String data = writeObjectToJson(sourceObj);
|
||||
data = data.replace("\"", "'");
|
||||
assertEquals(
|
||||
"{'list': ['value1', 'value2']}\n",
|
||||
data);
|
||||
assertThat(data, containsString("'list': ['value1', 'value2']"));
|
||||
|
||||
TestClassList targetObj = sendReceiveObject(sourceObj);
|
||||
TestClassList.assertEquals(sourceObj, targetObj);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue