org.xmlunit.diff.Diff Java Examples
The following examples show how to use
org.xmlunit.diff.Diff.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaEDIXMLStreamReaderTest.java From staedi with Apache License 2.0 | 11 votes |
@Test void testReadXml() throws Exception { XMLStreamReader xmlReader = getXmlReader("/x12/extraDelimiter997.edi"); xmlReader.next(); // Per StAXSource JavaDoc, put in START_DOCUMENT state TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); StringWriter result = new StringWriter(); transformer.transform(new StAXSource(xmlReader), new StreamResult(result)); String resultString = result.toString(); Diff d = DiffBuilder.compare(Input.fromFile("src/test/resources/x12/extraDelimiter997.xml")) .withTest(resultString).build(); assertTrue(!d.hasDifferences(), () -> "XML unexpectedly different:\n" + d.toString(new DefaultComparisonFormatter())); }
Example #2
Source File: DmnModelTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void assertModelEqualsFile(String expectedPath) throws Exception { File actualFile = tmpFolder.newFile(); Dmn.writeModelToFile(actualFile, modelInstance); File expectedFile = ReflectUtil.getResourceAsFile(expectedPath); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document actualDocument = docBuilder.parse(actualFile); Document expectedDocument = docBuilder.parse(expectedFile); Diff diff = DiffBuilder.compare(expectedDocument).withTest(actualDocument) .withNodeFilter(new Java9CDataWhitespaceFilter()) .checkForSimilar() .build(); if (diff.hasDifferences()) { String failMsg = "XML differs:\n" + diff.getDifferences() + "\n\nActual XML:\n" + Dmn.convertToString(modelInstance); fail(failMsg); } }
Example #3
Source File: XmlSchemaTestHelper.java From syndesis with Apache License 2.0 | 6 votes |
private static void compareMatchingElement(List<Element> sourceChildNodes, Element element) { final String type = element.getLocalName(); final String name = element.getAttribute(NAME_ATTRIBUTE); boolean matchFound = false; for (Element sourceElement : sourceChildNodes) { if (type.equals(sourceElement.getLocalName()) && name.equals(sourceElement.getAttribute(NAME_ATTRIBUTE))) { // compare matching element Diff diff = DiffBuilder.compare(Input.fromNode(sourceElement)) .withTest(Input.fromNode(sourceElement)) .ignoreComments() .ignoreWhitespace() .checkForIdentical() .build(); assertThat(diff.hasDifferences()) .overridingErrorMessage("Schema differences " + diff.toString()) .isFalse(); matchFound = true; } } if (!matchFound) { fail(String.format("Missing source element %s[name=%s]", type, name)); } }
Example #4
Source File: MavenMetadataGeneratorTests.java From artifactory-resource with Apache License 2.0 | 6 votes |
private Condition<File> xmlContent(URL expected) { return new Condition<File>("XML Content") { @Override public boolean matches(File actual) { Diff diff = DiffBuilder.compare(Input.from(expected)).withTest(Input.from(actual)).checkForSimilar() .ignoreWhitespace().build(); if (diff.hasDifferences()) { try { String content = new String(FileCopyUtils.copyToByteArray(actual)); throw new AssertionError(diff.toString() + "\n" + content); } catch (IOException ex) { throw new IllegalStateException(ex); } } return true; } }; }
Example #5
Source File: StaEDIXMLStreamReaderTest.java From staedi with Apache License 2.0 | 6 votes |
@Test void testTransactionElementWithXmlns() throws Exception { EDIInputFactory ediFactory = EDIInputFactory.newFactory(); ediFactory.setProperty(EDIInputFactory.XML_DECLARE_TRANSACTION_XMLNS, Boolean.TRUE); InputStream stream = getClass().getResourceAsStream("/x12/extraDelimiter997.edi"); ediReader = ediFactory.createEDIStreamReader(stream); XMLStreamReader xmlReader = ediFactory.createXMLStreamReader(ediReader); xmlReader.next(); // Per StAXSource JavaDoc, put in START_DOCUMENT state TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); StringWriter result = new StringWriter(); transformer.transform(new StAXSource(xmlReader), new StreamResult(result)); String resultString = result.toString(); Diff d = DiffBuilder.compare(Input.fromFile("src/test/resources/x12/extraDelimiter997-transaction-xmlns.xml")) .withTest(resultString).build(); assertTrue(!d.hasDifferences(), () -> "XML unexpectedly different:\n" + d.toString(new DefaultComparisonFormatter())); }
Example #6
Source File: MetadataTransferTest.java From archiva with Apache License 2.0 | 6 votes |
private void assertMetadataEquals( String expectedMetadataXml, Path actualFile ) throws Exception { assertNotNull( "Actual File should not be null.", actualFile ); assertTrue( "Actual file exists.", Files.exists(actualFile) ); StringWriter actualContents = new StringWriter(); FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager()); StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString()); ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader( null ).read( actualFileAsset ); RepositoryMetadataWriter.write( metadata, actualContents ); Diff detailedDiff = DiffBuilder.compare( expectedMetadataXml).withTest( actualContents.toString() ).checkForSimilar().build(); if ( detailedDiff.hasDifferences() ) { for ( Difference diff : detailedDiff.getDifferences() ) { System.out.println( diff ); } assertEquals( expectedMetadataXml, actualContents ); } // assertEquals( "Check file contents.", expectedMetadataXml, actualContents ); }
Example #7
Source File: MetadataToolsTest.java From archiva with Apache License 2.0 | 6 votes |
private void assertProjectMetadata( String expectedMetadata, ManagedRepositoryContent repository, ItemSelector reference ) throws LayoutException, IOException, SAXException, ParserConfigurationException { Path metadataFile = repository.getRepository().getRoot().getFilePath().resolve(tools.toPath( reference ) ); String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() ); Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build(); if ( detailedDiff.hasDifferences() ) { for ( Difference diff : detailedDiff.getDifferences() ) { System.out.println( diff ); } // If it isn't similar, dump the difference. assertEquals( expectedMetadata, actualMetadata ); } }
Example #8
Source File: MetadataToolsTest.java From archiva with Apache License 2.0 | 6 votes |
private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository, ItemSelector reference ) throws LayoutException, IOException, SAXException, ParserConfigurationException { Path metadataFile = repository.getRepository().getRoot().getFilePath().resolve( tools.toPath( reference ) ); String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() ); Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build(); if ( detailedDiff.hasDifferences() ) { for ( Difference diff : detailedDiff.getDifferences() ) { System.out.println( diff ); } // If it isn't similar, dump the difference. assertEquals( expectedMetadata, actualMetadata ); } }
Example #9
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withIgnoreWhitespaces_shouldSucceed() { // prepare testData String controlXml = "<a><b>Test Value</b></a>"; String testXml = "<a>\n <b>\n Test Value\n </b>\n</a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .ignoreWhitespace() .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #10
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withNormalizeWhitespaces_shouldSucceed() { // prepare testData String controlXml = "<a><b>Test Value</b></a>"; String testXml = "<a>\n <b>\n Test\n Value\n </b>\n</a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .normalizeWhitespace() .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #11
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withNormalizeAndIgnoreWhitespaces_shouldSucceed() { // prepare testData String controlXml = "<a><b>Test Value</b></a>"; String testXml = "<a>\n <b>\n Test\n Value\n </b>\n</a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .normalizeWhitespace() .ignoreWhitespace() .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #12
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withCheckForIdentical_shouldFail() { // prepare testData String controlXml = "<a>Test Value</a>"; String testXml = "<a><![CDATA[Test Value]]></a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .checkForIdentical() .build(); // validate result Assert.assertTrue(myDiff.toString(), myDiff.hasDifferences()); }
Example #13
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withIgnoreComments_shouldSucceed() { // prepare testData String controlXml = "<a><b><!-- A comment -->Test Value</b></a>"; String testXml = "<a><b><!-- An other comment -->Test Value</b></a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .ignoreComments() .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #14
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withIgnoreComments2_0_shouldSucceed() { // prepare testData String controlXml = "<a><b><!-- A comment -->Test Value</b></a>"; String testXml = "<a><b><!-- An other comment -->Test Value</b></a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .ignoreCommentsUsingXSLTVersion("2.0") .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #15
Source File: XMLManipulatorTest.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
@Test public void alterFile() throws Exception { String replacementGA = "com.rebuild:servlet-api"; String tomcatPath = "//include[starts-with(.,'org.apache.tomcat')]"; File target = tf.newFile(); FileUtils.copyFile( xmlFile, target ); Project project = new Project( target, TestUtils.getDummyModel() ); xmlManipulator.internalApplyChanges( project, new XMLState.XMLOperation( target.getName(), tomcatPath, replacementGA) ); Diff diff = DiffBuilder.compare( fromFile( xmlFile ) ).withTest( fromFile( target ) ).build(); assertTrue (diff.toString(), diff.hasDifferences()); String xpathForHamcrest = "/*/*/*/*/*[starts-with(.,'com.rebuild') and local-name() = 'include']"; Iterable<Node> i = new JAXPXPathEngine( ).selectNodes( xpathForHamcrest, fromFile( target ).build() ); int count = 0; for ( Node anI : i ) { count++; assertTrue( anI.getTextContent().startsWith( "com.rebuild:servlet-api" ) ); } assertEquals(1, count); }
Example #16
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withIgnoreECW_shouldSucceed() { // prepare testData String controlXml = "<a><b>Test Value</b></a>"; String testXml = "<a>\n <b>Test Value</b>\n</a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .ignoreElementContentWhitespace() .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #17
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withCustomDifferenceEvaluator_shouldNotEvaluateSimilar() { // prepare testData final String control = "<a><b><![CDATA[abc]]></b></a>"; final String test = "<a><b>abc</b></a>"; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .withDifferenceEvaluator(new IgnoreAttributeDifferenceEvaluator("attr")) .checkForSimilar() .build(); // validate result Assert.assertTrue(myDiff.toString(), myDiff.hasDifferences()); Assert.assertThat(ComparisonResult.DIFFERENT, is(myDiff.getDifferences().iterator().next().getResult())); }
Example #18
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withDifferenceEvaluator_shouldNotInterfereWithSimilar() { // prepare testData final String control = "<a><b><![CDATA[abc]]></b></a>"; final String test = "<a><b>abc</b></a>"; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .withDifferenceEvaluator( DifferenceEvaluators.chain(DifferenceEvaluators.Default, new IgnoreAttributeDifferenceEvaluator("attr"))) .checkForSimilar() .build(); // validate result Assert.assertFalse(myDiff.toString(), myDiff.hasDifferences()); }
Example #19
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withDifferenceListener_shouldCallListener() { // prepare testData final String control = "<a><b attr=\"abc\"></b></a>"; final String test = "<a><b attr=\"xyz\"></b></a>"; final List<Difference> diffs = new ArrayList<Difference>(); final ComparisonListener comparisonListener = new ComparisonListener() { @Override public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) { diffs.add(new Difference(comparison, outcome)); } }; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .withDifferenceListeners(comparisonListener) .build(); // validate result Assert.assertTrue(myDiff.toString(), myDiff.hasDifferences()); assertThat(diffs.size(), is(1)); assertThat(diffs.get(0).getResult(), is(ComparisonResult.DIFFERENT)); assertThat(diffs.get(0).getComparison().getType(), is(ComparisonType.ATTR_VALUE)); }
Example #20
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withComparisonListener_shouldCallListener() { // prepare testData final String control = "<a><b attr=\"abc\"></b></a>"; final String test = "<a><b attr=\"xyz\"></b></a>"; final List<Difference> diffs = new ArrayList<Difference>(); final ComparisonListener comparisonListener = new ComparisonListener() { @Override public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) { diffs.add(new Difference(comparison, outcome)); } }; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .withComparisonListeners(comparisonListener) .build(); // validate result Assert.assertTrue(myDiff.toString(), myDiff.hasDifferences()); assertThat(diffs.size(), greaterThan(1)); }
Example #21
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withIgnoreComments1_0_shouldSucceed() { // prepare testData String controlXml = "<a><b><!-- A comment -->Test Value</b></a>"; String testXml = "<a><b><!-- An other comment -->Test Value</b></a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .ignoreCommentsUsingXSLTVersion("1.0") .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #22
Source File: XmlSteps.java From vividus with Apache License 2.0 | 6 votes |
/** * Checks if XML is equal to expected XML * @param xml XML * @param expectedXml Expected XML */ @Then("XML `$xml` is equal to `$expectedXml`") public void compareXmls(String xml, String expectedXml) { Diff diff = DiffBuilder.compare(expectedXml).withTest(xml) .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndAllAttributes)) .ignoreWhitespace() .checkForSimilar() .build(); Iterable<?> allDifferences = diff.getDifferences(); if (allDifferences.iterator().hasNext()) { StringBuilder stringBuilder = new StringBuilder(); for (Object difference : allDifferences) { stringBuilder.append(difference).append(System.lineSeparator()); } softAssert.recordFailedAssertion(stringBuilder.toString()); } }
Example #23
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 6 votes |
@Test public void testDiff_withCheckForSimilar_shouldSucceed() { // prepare testData String controlXml = "<a>Test Value</a>"; String testXml = "<a><![CDATA[Test Value]]></a>"; // run test Diff myDiff = DiffBuilder.compare(Input.fromString(controlXml).build()) .withTest(Input.fromString(testXml).build()) .checkForSimilar() .build(); // validate result Assert.assertFalse("XML similar " + myDiff.toString(), myDiff.hasDifferences()); }
Example #24
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void usesCustomComparisonFormatter() { String control = "<a><b></b><c/></a>"; String test = "<a><b></b><c/><d/></a>"; Diff myDiff = DiffBuilder.compare(control).withTest(test) .withComparisonController(ComparisonControllers.StopWhenDifferent) .withComparisonFormatter(new DummyFormatter()) .build(); Assert.assertEquals("foo", myDiff.toString()); }
Example #25
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void usesDocumentBuilderFactoryWhenNormalizingWhitespace() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setFeature("http://xml.org/sax/features/validation", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Diff d = DiffBuilder.compare(Input.fromString( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n" + " \"http://example.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head></head>\n" + " <body>some content 1</body>\n" + "</html>")) .withTest(Input.fromString( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n" + " \"http://example.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head></head>\n" + " <body>some content 2</body>\n" + "</html>")) .withDocumentBuilderFactory(dbf) .normalizeWhitespace() .build(); Assert.assertTrue(d.hasDifferences()); }
Example #26
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Would cause an error because * http://example.org/TR/xhtml1/DTD/xhtml1-transitional.dtd * doesn't exist if the DocumentBuilderFactory tried to resolve * the DTD. * * @see "https://github.com/xmlunit/xmlunit/issues/86" */ @Test public void usesDocumentBuilderFactoryWhenIgnoringWhitespace() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setFeature("http://xml.org/sax/features/validation", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Diff d = DiffBuilder.compare(Input.fromString( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n" + " \"http://example.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head></head>\n" + " <body>some content 1</body>\n" + "</html>")) .withTest(Input.fromString( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n" + " \"http://example.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head></head>\n" + " <body>some content 2</body>\n" + "</html>")) .withDocumentBuilderFactory(dbf) .ignoreWhitespace() .build(); Assert.assertTrue(d.hasDifferences()); }
Example #27
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void usesCustomComparisonFormatterForDifferences() { String control = "<a><b></b><c/></a>"; String test = "<a><b></b><c/><d/></a>"; Diff myDiff = DiffBuilder.compare(control).withTest(test) .withComparisonController(ComparisonControllers.StopWhenDifferent) .withComparisonFormatter(new DummyFormatter()) .build(); Assert.assertEquals("foo (DIFFERENT)", myDiff.getDifferences().iterator().next().toString()); }
Example #28
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void testDiff_withAttributeDifferences() { // prepare testData final String control = "<a><b attr1=\"abc\" attr2=\"def\"></b></a>"; final String test = "<a><b attr1=\"uvw\" attr2=\"def\"></b></a>"; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .withComparisonController(ComparisonControllers.StopWhenDifferent) .build(); // validate result Assert.assertTrue(myDiff.hasDifferences()); assertThat(count(myDiff.getDifferences()), is(1)); // run test Diff myDiffWithFilter = DiffBuilder.compare(control).withTest(test) .withAttributeFilter(new Predicate<Attr>() { @Override public boolean test(Attr a) { return !"attr1".equals(a.getName()); } }) .withComparisonController(ComparisonControllers.StopWhenDifferent) .build(); // validate result Assert.assertFalse(myDiffWithFilter.hasDifferences()); }
Example #29
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void testDiff_withDefaultComparisonController_shouldReturnAllDifferences() { // prepare testData final String control = "<a><b attr1=\"abc\" attr2=\"def\"></b></a>"; final String test = "<a><b attr1=\"uvw\" attr2=\"xyz\"></b></a>"; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .build(); // validate result Assert.assertTrue(myDiff.hasDifferences()); assertThat(count(myDiff.getDifferences()), is(2)); }
Example #30
Source File: DiffBuilderTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void testDiff_withStopWhenDifferentComparisonController_shouldReturnOnlyFirstDifference() { // prepare testData final String control = "<a><b attr1=\"abc\" attr2=\"def\"></b></a>"; final String test = "<a><b attr1=\"uvw\" attr2=\"xyz\"></b></a>"; // run test Diff myDiff = DiffBuilder.compare(control).withTest(test) .withComparisonController(ComparisonControllers.StopWhenDifferent) .build(); // validate result Assert.assertTrue(myDiff.hasDifferences()); assertThat(count(myDiff.getDifferences()), is(1)); }