|
11 | 11 | import org.junit.Test; |
12 | 12 |
|
13 | 13 | public class JSONTest { |
| 14 | + @Test |
| 15 | + public void testConstructor() { |
| 16 | + final JSONObject expected = new JSONObject("{\"myKey\":10}"); |
| 17 | + |
| 18 | + @SuppressWarnings("rawtypes") |
| 19 | + Map myRawC = Collections.singletonMap("myKey", Integer.valueOf(10)); |
| 20 | + JSONObject jaRaw = new JSONObject(myRawC); |
| 21 | + |
| 22 | + Map<String, Object> myCStrObj = Collections.singletonMap("myKey", (Object) Integer.valueOf(10)); |
| 23 | + JSONObject jaStrObj = new JSONObject(myCStrObj); |
| 24 | + |
| 25 | + Map<String, Integer> myCStrInt = Collections.singletonMap("myKey", Integer.valueOf(10)); |
| 26 | + JSONObject jaStrInt = new JSONObject(myCStrInt); |
| 27 | + |
| 28 | + Map<?, ?> myCObjObj = Collections.singletonMap((Object) "myKey", (Object) Integer.valueOf(10)); |
| 29 | + JSONObject jaObjObj = new JSONObject(myCObjObj); |
| 30 | + |
| 31 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaRaw)); |
| 32 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaStrObj)); |
| 33 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaStrInt)); |
| 34 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaObjObj)); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testPutMap() { |
| 39 | + final JSONObject expected = new JSONObject("{\"myMap\":{\"myKey\":10}}"); |
| 40 | + |
| 41 | + @SuppressWarnings("rawtypes") |
| 42 | + Map myRawC = Collections.singletonMap("myKey", Integer.valueOf(10)); |
| 43 | + JSONObject jaRaw = new JSONObject(); |
| 44 | + jaRaw.put("myMap", myRawC); |
| 45 | + |
| 46 | + Map<String, Object> myCStrObj = Collections.singletonMap("myKey", (Object) Integer.valueOf(10)); |
| 47 | + JSONObject jaStrObj = new JSONObject(); |
| 48 | + jaStrObj.put("myMap", myCStrObj); |
| 49 | + |
| 50 | + Map<String, Integer> myCStrInt = Collections.singletonMap("myKey", Integer.valueOf(10)); |
| 51 | + JSONObject jaStrInt = new JSONObject(); |
| 52 | + jaStrInt.put("myMap", myCStrInt); |
| 53 | + |
| 54 | + Map<?, ?> myCObjObj = Collections.singletonMap((Object) "myKey", (Object) Integer.valueOf(10)); |
| 55 | + JSONObject jaObjObj = new JSONObject(); |
| 56 | + jaObjObj.put("myMap", myCObjObj); |
| 57 | + |
| 58 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaRaw)); |
| 59 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaStrObj)); |
| 60 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaStrInt)); |
| 61 | + assertTrue("The RAW Collection should give me the same as the Typed Collection", expected.similar(jaObjObj)); |
| 62 | + } |
| 63 | + |
14 | 64 | @Test |
15 | 65 | public void testMapWithNullValue() { |
16 | 66 | Map<String, Object> map = new HashMap<String, Object>(); |
@@ -50,7 +100,7 @@ public void testPutNull() { |
50 | 100 | assertTrue("jsonObject should be empty", jsonObjectRemove.isEmpty()); |
51 | 101 |
|
52 | 102 | JSONObject jsonObjectPutNull = new JSONObject(str); |
53 | | - jsonObjectPutNull.put("myKey", (Object) null); |
| 103 | + jsonObjectPutNull.put("myKey", null); |
54 | 104 | assertTrue("jsonObject should NOT be empty", !jsonObjectPutNull.isEmpty()); |
55 | 105 | } |
56 | 106 |
|
|
0 commit comments