@Test public void testPrettyPrint() throws SAXException, IOException, ParserConfigurationException { when(adsApiConfiguration.getSensitiveXPaths()).thenReturn(new String[] {TEST_SENSITIVE_XPATH}); String prettyPrintedXml = createPrettyPrinter().prettyPrint(TEST_XML); String expectedXml = TEST_XML.replace("moe", "REDACTED"); Document expectedDocument = XMLUnit.getControlDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(expectedXml))); Document actualDocument = XMLUnit.getTestDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(prettyPrintedXml))); XMLAssert.assertXMLEqual( XMLUnit.getWhitespaceStrippedDocument(expectedDocument), XMLUnit.getWhitespaceStrippedDocument(actualDocument)); }
@Override public String prettyPrint(String xml) { if (xml == null) { return xml; } Source xmlSource = sanitizeXml(xml); if (xmlSource == null) { xmlSource = new StreamSource(new StringReader(xml)); } String formattedXml = formatXml(xmlSource); return formattedXml != null ? formattedXml : xml; }
PrettyPrinter implements PrettyPrinterInterface { @Override public String prettyPrint(String xml) { if (xml == null) { return xml; } Source xmlSource = sanitizeXml(xml); if (xmlSource == null) { xmlSource = new StreamSource(new StringReader(xml)); } String formattedXml = formatXml(xmlSource); return formattedXml != null ? formattedXml : xml; } }
PrettyPrinter implements PrettyPrinterInterface { @Override public String prettyPrint(String xml) { if (xml == null) { return xml; } Source xmlSource = sanitizeXml(xml); if (xmlSource == null) { xmlSource = new StreamSource(new StringReader(xml)); } String formattedXml = formatXml(xmlSource); return formattedXml != null ? formattedXml : xml; } @Inject  PrettyPrinter(
      AdsApiConfiguration adsApiConfiguration,
      @Named("libLogger") Logger libLogger,
      Supplier<XPath> xpathSupplier,
      Supplier<Transformer> transformerSupplier,
      Supplier<DocumentBuilder> documentBuilderSupplier); }
PrettyPrinter implements PrettyPrinterInterface { @Override public String prettyPrint(String xml) { if (xml == null) { return xml; } Source xmlSource = sanitizeXml(xml); if (xmlSource == null) { xmlSource = new StreamSource(new StringReader(xml)); } String formattedXml = formatXml(xmlSource); return formattedXml != null ? formattedXml : xml; } @Inject  PrettyPrinter(
      AdsApiConfiguration adsApiConfiguration,
      @Named("libLogger") Logger libLogger,
      Supplier<XPath> xpathSupplier,
      Supplier<Transformer> transformerSupplier,
      Supplier<DocumentBuilder> documentBuilderSupplier); @Override String prettyPrint(String xml); }
PrettyPrinter implements PrettyPrinterInterface { @Override public String prettyPrint(String xml) { if (xml == null) { return xml; } Source xmlSource = sanitizeXml(xml); if (xmlSource == null) { xmlSource = new StreamSource(new StringReader(xml)); } String formattedXml = formatXml(xmlSource); return formattedXml != null ? formattedXml : xml; } @Inject  PrettyPrinter(
      AdsApiConfiguration adsApiConfiguration,
      @Named("libLogger") Logger libLogger,
      Supplier<XPath> xpathSupplier,
      Supplier<Transformer> transformerSupplier,
      Supplier<DocumentBuilder> documentBuilderSupplier); @Override String prettyPrint(String xml);  }