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\"></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() |
CompareAssert |
ignoreCommentsUsingXSLTVersion(String xsltVersion) |
CompareAssert |
ignoreElementContentWhitespace() |
CompareAssert |
ignoreWhitespace() |
CompareAssert |
normalizeWhitespace() |
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.
|
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, setCustomRepresentation, throwAssertionError, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
public CompareAssert withNodeMatcher(NodeMatcher nodeMatcher)
Example with DefaultNodeMatcher
:
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
withNodeMatcher
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.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())) ....
withDifferenceEvaluator
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.withDifferenceEvaluator(DifferenceEvaluator)
public CompareAssert withComparisonController(ComparisonController comparisonController)
ComparisonControllers#Default
with your own ComparisonController.
Example use:
.withComparisonController(ComparisonControllers.StopWhenDifferent)
withComparisonController
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.withComparisonController(ComparisonController)
public CompareAssert withComparisonListeners(ComparisonListener... comparisonListeners)
withComparisonListeners
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.withComparisonListeners(ComparisonListener...)
public CompareAssert withDifferenceListeners(ComparisonListener... comparisonListeners)
ComparisonResult.EQUAL
.withDifferenceListeners
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.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.
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
.
withAttributeFilter
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.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.
withNodeFilter
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.withNodeFilter(Predicate)
public CompareAssert withComparisonFormatter(ComparisonFormatter formatter)
withComparisonFormatter
in interface DifferenceEngineConfigurer<CompareAssert>
DiffBuilder.withComparisonFormatter(ComparisonFormatter)
public CompareAssert withDocumentBuilderFactory(DocumentBuilderFactory f)
public CompareAssert ignoreWhitespace()
DiffBuilder.ignoreWhitespace()
public CompareAssert normalizeWhitespace()
DiffBuilder.normalizeWhitespace()
public CompareAssert ignoreElementContentWhitespace()
public CompareAssert ignoreComments()
DiffBuilder.ignoreComments()
public CompareAssert ignoreCommentsUsingXSLTVersion(String xsltVersion)
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()
Copyright © 2001–2019 XMLUnit. All rights reserved.