public class CompareAssert extends org.assertj.core.api.AbstractAssert<SELF,ACTUAL> implements DifferenceEngineConfigurer<CompareAssert>
Simple Example
import static org.xmlunit.assertj.XmlAssert.assertThat; final String control = "<a><b attr=\"abc\"></b></a>"; final String test = "<a><b attr=\"xyz\"NodeAssertFactory></b></a>"; assertThat(test).and(control).areIdentical(); assertThat(test).and(control).areNotSimilar();
| Modifier and Type | Method and Description |
|---|---|
CompareAssert |
areIdentical()
Check if actual and control XMLs are identical.
|
CompareAssert |
areNotIdentical()
Check if actual and control XMLs are not identical.
|
CompareAssert |
areNotSimilar()
Check if actual and control XMLs are not similar.
|
CompareAssert |
areSimilar()
Check if actual and control XMLs are similar.
|
CompareAssert |
ignoreChildNodesOrder()
Equivalent for
|
CompareAssert |
ignoreComments()
Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.
|
CompareAssert |
ignoreCommentsUsingXSLTVersion(String xsltVersion)
Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.
|
CompareAssert |
ignoreElementContentWhitespace()
Ignore element content whitespace by removing all text nodes solely consisting of whitespace.
|
CompareAssert |
ignoreWhitespace()
Ignore whitespace by removing all empty text nodes and trimming the non-empty ones.
|
protected boolean |
isElementOfCustomAssert(StackTraceElement stackTraceElement) |
CompareAssert |
normalizeWhitespace()
Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.
|
CompareAssert |
withAttributeFilter(Predicate<Attr> attributeFilter)
Registers a filter for attributes.
|
CompareAssert |
withComparisonController(ComparisonController comparisonController)
Replace the
ComparisonControllers.Default with your own ComparisonController. |
CompareAssert |
withComparisonFormatter(ComparisonFormatter formatter)
Sets a non-default formatter for the differences found.
|
CompareAssert |
withComparisonListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison.
|
CompareAssert |
withDifferenceEvaluator(DifferenceEvaluator differenceEvaluator)
Provide your own custom
DifferenceEvaluator implementation. |
CompareAssert |
withDifferenceListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison with
outcome other than
ComparisonResult.EQUAL. |
CompareAssert |
withDocumentBuilderFactory(DocumentBuilderFactory f)
|
CompareAssert |
withNamespaceContext(Map<String,String> prefix2Uri)
Establish a namespace context that will be used in
Comparison.Detail#getXPath. |
CompareAssert |
withNodeFilter(Predicate<Node> nodeFilter)
Registers a filter for nodes.
|
CompareAssert |
withNodeMatcher(NodeMatcher nodeMatcher)
Sets the strategy for selecting nodes to compare.
|
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorpublic CompareAssert withNodeMatcher(NodeMatcher nodeMatcher)
Example with DefaultNodeMatcher:
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
This overwrites any NodeMatcher set via earlier invocations of withNodeMatcher.
withNodeMatcher in interface DifferenceEngineConfigurer<CompareAssert>nodeMatcher - the NodeMatcher to useDiffBuilder.withNodeMatcher(NodeMatcher)public CompareAssert withDifferenceEvaluator(DifferenceEvaluator differenceEvaluator)
DifferenceEvaluator implementation.
This overwrites the Default DifferenceEvaluator.
If you want use your custom DifferenceEvaluator in
combination with the default or another DifferenceEvaluator you
should use DifferenceEvaluators.chain(DifferenceEvaluator...) or DifferenceEvaluators.first(DifferenceEvaluator...) to combine
them:
.withDifferenceEvaluator(
DifferenceEvaluators.chain(
DifferenceEvaluators.Default,
new MyCustomDifferenceEvaluator()))
....
This overwrites any DifferenceEvaluator set via earlier invocations of withDifferenceEvaluator.
withDifferenceEvaluator in interface DifferenceEngineConfigurer<CompareAssert>differenceEvaluator - the DifferenceEvaluator to useDiffBuilder.withDifferenceEvaluator(DifferenceEvaluator)public CompareAssert withComparisonController(ComparisonController comparisonController)
ComparisonControllers.Default with your own ComparisonController.
Example use:
.withComparisonController(ComparisonControllers.StopWhenDifferent)
This overwrites any ComparisonController set via earlier invocations of withComparisonController.
withComparisonController in interface DifferenceEngineConfigurer<CompareAssert>comparisonController - ComparisonController to useDiffBuilder.withComparisonController(ComparisonController)public CompareAssert withComparisonListeners(ComparisonListener... comparisonListeners)
withComparisonListeners in interface DifferenceEngineConfigurer<CompareAssert>comparisonListeners - ComparisonListeners to useDiffBuilder.withComparisonListeners(ComparisonListener...)public CompareAssert withDifferenceListeners(ComparisonListener... comparisonListeners)
ComparisonResult.EQUAL.
This overwrites any ComparisonListeners set via earlier invocations of withDifferenceListeners.
withDifferenceListeners in interface DifferenceEngineConfigurer<CompareAssert>comparisonListeners - ComparisonListeners to useDiffBuilder.withDifferenceListeners(ComparisonListener...)public CompareAssert withNamespaceContext(Map<String,String> prefix2Uri)
Comparison.Detail#getXPath.
Without a namespace context (or with an empty context) the XPath expressions will only use local names for elements and attributes.
This overwrites any Map set via earlier invocations of withNamespaceContext.
withNamespaceContext in interface DifferenceEngineConfigurer<CompareAssert>prefix2Uri - mapping between prefix and namespace URIDiffBuilder.withNamespaceContext(Map)public CompareAssert withAttributeFilter(Predicate<Attr> attributeFilter)
Only attributes for which the predicate returns true are part of the comparison. By default all attributes are considered.
The "special" namespace, namespace-location and
schema-instance-type attributes can not be ignored this way.
If you want to suppress comparison of them you'll need to
implement DifferenceEvaluator.
This overwrites any Predicate set via earlier invocations of withAttributeFilter.
withAttributeFilter in interface DifferenceEngineConfigurer<CompareAssert>attributeFilter - attribute filter to useDiffBuilder.withAttributeFilter(Predicate)public CompareAssert withNodeFilter(Predicate<Node> nodeFilter)
Only nodes for which the predicate returns true are part of the comparison. By default nodes that are not document types are considered.
This overwrites any Predicate set via earlier invocations of withNodeFilter.
withNodeFilter in interface DifferenceEngineConfigurer<CompareAssert>nodeFilter - node filter to useDiffBuilder.withNodeFilter(Predicate)public CompareAssert withComparisonFormatter(ComparisonFormatter formatter)
This overwrites any ComparisonFormatter set via earlier invocations of withComparisonFormatter.
withComparisonFormatter in interface DifferenceEngineConfigurer<CompareAssert>formatter - formatter to useDiffBuilder.withComparisonFormatter(ComparisonFormatter)public CompareAssert withDocumentBuilderFactory(DocumentBuilderFactory f)
f - the DocumentBuilderFactory to useDiffBuilder.withDocumentBuilderFactory(DocumentBuilderFactory)public CompareAssert ignoreWhitespace()
DiffBuilder.ignoreWhitespace()public CompareAssert normalizeWhitespace()
DiffBuilder.normalizeWhitespace()public CompareAssert ignoreElementContentWhitespace()
DiffBuilder.ignoreElementContentWhitespace()public CompareAssert ignoreComments()
DiffBuilder.ignoreComments()public CompareAssert ignoreCommentsUsingXSLTVersion(String xsltVersion)
xsltVersion - use this version for the stylesheetDiffBuilder.ignoreCommentsUsingXSLTVersion(String)public CompareAssert ignoreChildNodesOrder()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.withDifferenceEvaluator(
chain(
Default,
DifferenceEvaluators.downgradeDifferencesToEqual(ComparisonType.CHILD_NODELIST_SEQUENCE)));
DiffBuilder.withNodeMatcher(NodeMatcher)public CompareAssert areIdentical()
ComparisonControllers.StopWhenSimilar is used.AssertionError - if the test value is invalidAssertionError - if the control value is invalidDiffBuilder.checkForIdentical()public CompareAssert areNotIdentical()
ComparisonControllers.StopWhenSimilar is used.AssertionError - if the test value is invalidAssertionError - if the control value is invalidDiffBuilder.checkForSimilar()public CompareAssert areSimilar()
ComparisonControllers.StopWhenDifferent is used.AssertionError - if the test value is invalidAssertionError - if the control value is invalidDiffBuilder.checkForSimilar()public CompareAssert areNotSimilar()
ComparisonControllers.StopWhenDifferent is used.AssertionError - if the test value is invalidAssertionError - if the control value is invalidDiffBuilder.checkForSimilar()protected boolean isElementOfCustomAssert(StackTraceElement stackTraceElement)
isElementOfCustomAssert in class org.assertj.core.api.AbstractAssert<SELF extends org.xmlunit.assertj.CustomAbstractAssert<SELF,ACTUAL>,ACTUAL>Copyright © 2001–2024 XMLUnit. All rights reserved.