JsonParserUtils { public static Map<String, Object> jsonStringToMap(String jsonString) { notNull(jsonString, "jsonString can not be null"); return jsonObjectToMap(new JSONObject(jsonString)); }  static Map<String, Object> jsonStringToMap(String jsonString); static Map<String, Object> jsonObjectToMap(JSONObject jsonObject);  }
@Test(groups = SMALL) public void testJsonEmptyObjectStringToMapReturnsEmptyMap() { String jsonString = "{}"; Map<String, Object> parsedMap = jsonStringToMap(jsonString); assertEquals(parsedMap.size(), 0); }
@Test(groups = SMALL) public void testJsonStringToMapCreatesMapWithTheSameProperties() { String jsonString = "{'key': 'value', 'key2': 1}"; Map<String, Object> parsedMap = jsonStringToMap(jsonString); assertEquals(parsedMap.get("key"), "value"); assertEquals(parsedMap.get("key2"), 1); }
@Test(groups = SMALL, expectedExceptions = JSONException.class) public void testJsonStringToMapThrowsExceptionForNonJsonString() { jsonStringToMap(""); }
@Test(groups = SMALL, expectedExceptions = IllegalArgumentException.class) public void testJsonStringToMapThrowsExceptionForNullString() { jsonStringToMap(null); }