XmlConverter implements Converter { @Override public String convert(final String xml, final String name) { String json; try { json = XML.toJSONObject(xml).toString(); } catch (JSONException e) { logger.debug("Couldn't convert to JSON the following XML: " + xml, e); json = ""; } return json; }  @Override String convert(final String xml, final String name);  }
@Test public void testGetJsonFormWithInvalidXmlShouldReturnEmptyJsonObject() { String json = underTest.convert("empty", NOT_USED); assertEquals(json, "{}"); }
@Test public void testGetJsonFormWithInvalidSyntaxShouldReturnEmptyString() { String json = underTest.convert("<><>", NOT_USED); assertEquals(json, ""); }
@Test public void testGetJsonFormWithValidJsonShouldReturnJson() { String json = underTest.convert("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><field1>value1</field1></root>", NOT_USED); assertEquals(json, "{\"root\":{\"field1\":\"value1\"}}"); }