From fcb8048038a31bc9683d777d36c0ef3c114a44fd Mon Sep 17 00:00:00 2001 From: stleary Date: Thu, 7 May 2015 23:04:44 -0500 Subject: [PATCH] deepened the testing a little bit, slow going --- JSONObjectTest.java | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/JSONObjectTest.java b/JSONObjectTest.java index 1aa19d7..6ef9b02 100644 --- a/JSONObjectTest.java +++ b/JSONObjectTest.java @@ -85,7 +85,6 @@ public class JSONObjectTest { /** * JSONObjects can be built from a Map. * In this test all of the map entries are valid JSON types. - * TODO: test with map values that are not valid JSON types */ String expectedStr = "{"+ @@ -109,6 +108,28 @@ public class JSONObjectTest { Util.compareActualVsExpectedJsonObjects(jsonObject, expectedJsonObject); } + @Test + public void jsonObjectByMapWithUnsupportedValues() { + /** + * JSONObjects can be built from a Map. + * In this test the map entries are not valid JSON types. + * The actual conversion is kind of interesting. + */ + String expectedStr = + "{"+ + "\"key1\":{},"+ + "\"key2\":\"java.lang.Exception\""+ + "}"; + Map jsonMap = new HashMap(); + // Just insert some random objects + jsonMap.put("key1", new CDL()); + jsonMap.put("key2", new Exception()); + + JSONObject jsonObject = new JSONObject(jsonMap); + JSONObject expectedJsonObject = new JSONObject(expectedStr); + Util.compareActualVsExpectedJsonObjects(jsonObject, expectedJsonObject); + } + @Test public void jsonObjectByMapWithNullValue() { /** @@ -151,9 +172,8 @@ public class JSONObjectTest { @Test public void jsonObjectByBean() { /** - * JSONObject built from a bean. In this case all of the - * bean properties are valid JSON types - * TODO: test with bean fields that are not valid JSON types + * JSONObject built from a bean. In this case all but one of the + * bean getters return valid JSON types */ String expectedStr = "{"+ @@ -162,7 +182,8 @@ public class JSONObjectTest { "\"stringKey\":\"hello world!\","+ "\"complexStringKey\":\"h\be\tllo w\u1234orld!\","+ "\"intKey\":42,"+ - "\"doubleKey\":-23.45e7"+ + "\"doubleKey\":-23.45e7,"+ + "\"stringReaderKey\":{}"+ "}"; MyBean myBean = new MyBean(); JSONObject jsonObject = new JSONObject(myBean);