### Question:
BeanXmlConverter implements BeanConverter { public String convertToXml(Object obj) { StringWriter outputWriter = new StringWriter(); BeanWriter writer = new BeanWriter(outputWriter); IntrospectionConfiguration configuration = writer.getXMLIntrospector().getConfiguration(); configuration.setAttributesForPrimitives(false); configuration.setWrapCollectionsInElement(true); writer.getBindingConfiguration().setMapIDs(false); writer.setEndOfLine(""); writer.setWriteEmptyElements(false); String toReturn = null; try { writer.write("response", obj); toReturn = outputWriter.toString(); if (LOG.isLoggable(Level.FINEST)) LOG.finest("XML is: " + toReturn + "\n **** \n\n"); } catch (SAXException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } catch (IntrospectionException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } finally { try { writer.close(); } catch (IOException e) { if (LOG.isLoggable(Level.FINEST)) LOG.log(Level.FINEST, e.getMessage(), e); } } return toReturn; }  String getContentType(); String convertToString(Object pojo); String convertToXml(Object obj); @SuppressWarnings("unchecked") T convertToObject(String xml, Class<T> className); void append(Appendable buf, Object pojo);  }### Answer:
@Test public void testCarToXml() throws Exception { String xml = beanXmlConverter.convertToXml(car); XMLUnit.setIgnoreWhitespace(true); Diff diff; diff = new Diff(Model.Car.DEFAULT_XML, xml); diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); XMLAssert.assertXMLEqual(diff, true); }
@Test public void testMapsToXml() throws Exception { Map<String, Map<String, String>> map = Maps.newTreeMap(); Map<String, String> item1Map = ImmutableMap.of("value","1"); map.put("item1", item1Map); Map<String, String> item2Map = ImmutableMap.of("value", "2"); map.put("item2", item2Map); String xml = beanXmlConverter.convertToXml(map); XmlUtil.parse(xml); String expectedXml = "<response>" + "<empty>false</empty>" + "<entry>" + "<key>item1</key>" + "<value>" + "<empty>false</empty>" + "<entry>" + "<key>value</key>" + "<value>1</value>" + "</entry>" + "</value>" + "</entry>" + "<entry>" + "<key>item2</key>" + "<value>" + "<empty>false</empty>" + "<entry>" + "<key>value</key>" + "<value>2</value>" + "</entry>" + "</value>" + "</entry>" + "</response>"; assertEquals(expectedXml, StringUtils.deleteWhitespace(xml)); }