/** * Tests that when the Transformer supplier returns null, request ID is still extracted, but * formatting is skipped. */ @Test public void testTransformerSupplierReturnsNull() { when(transformerSupplier.get()).thenReturn(null); String prettyPrintedXml = createPrettyPrinter().prettyPrint(TEST_XML); assertSame( "XML should not be formatted if Supplier<Transformer>.get returns null", TEST_XML, prettyPrintedXml); }
/** * Tests that when the XPath supplier returns null, request ID is not extracted, but formatting * still occurs. */ @Test public void testXPathSupplierReturnsNull() { when(xpathSupplier.get()).thenReturn(null); String prettyPrintedXml = createPrettyPrinter().prettyPrint(TEST_XML); assertNotNull(prettyPrintedXml); assertNotEquals( "XML should still be formatted, even if XPathSupplier.get returns null", TEST_XML, prettyPrintedXml); } }
/** * Tests that when the DocumentBuilder supplier returns null, request ID is not extracted, but * formatting still occurs. */ @Test public void testDocumentBuilderSupplierReturnsNull() { when(documentBuilderSupplier.get()).thenReturn(null); String prettyPrintedXml = createPrettyPrinter().prettyPrint(TEST_XML); assertNotNull(prettyPrintedXml); assertNotEquals( "XML should still be formatted, even if Supplier<DocumentBuilder>.get returns null", TEST_XML, prettyPrintedXml); }
/** * Tests that pretty printing works properly under normal circumstances. */ @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)); }