@Test public void testParseJson() throws Exception { Map<String, Object> jsonParams = new HashMap<String, Object>(); jsonParams.put("author", "John B. Smith"); jsonParams.put("year", "2000"); String s = JSONUtils.buildJSON(jsonParams); Map<String, Object> map = JSONUtils.parseJSON(s); Assert.assertEquals("John B. Smith", map.get("author")); Assert.assertEquals("2000", map.get("year")); }
@Test public void testBuildJSON() throws Exception { Map<String, Object> params = new HashMap<String, Object>(); params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST); String json = JSONUtils.buildJSON(params); JSONObject obj = new JSONObject(json); AbstractXMLStreamReader reader = new MappedXMLStreamReader(obj); Assert.assertEquals(XMLStreamReader.START_ELEMENT, reader.next()); Assert.assertEquals(OAuthError.OAUTH_ERROR, reader.getName().getLocalPart()); Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, reader.getText()); Assert.assertEquals(XMLStreamReader.CHARACTERS, reader.next()); Assert.assertEquals(XMLStreamReader.END_ELEMENT, reader.next()); Assert.assertEquals(XMLStreamReader.END_DOCUMENT, reader.next()); }