Class CompareAssert
- All Implemented Interfaces:
org.assertj.core.api.Assert<CompareAssert,
,Object> org.assertj.core.api.Descriptable<CompareAssert>
,org.assertj.core.api.ExtensionPoints<CompareAssert,
,Object> 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();
- Since:
- XMLUnit 2.8.1
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Method Summary
Modifier and TypeMethodDescriptionCheck if actual and control XMLs are identical.Check if actual and control XMLs are not identical.Check if actual and control XMLs are not similar.Check if actual and control XMLs are similar.Equivalent forWill remove all comment-Tags "<!ignoreCommentsUsingXSLTVersion
(String xsltVersion) Will remove all comment-Tags "<!Ignore element content whitespace by removing all text nodes solely consisting of whitespace.Ignore whitespace by removing all empty text nodes and trimming the non-empty ones.protected boolean
isElementOfCustomAssert
(StackTraceElement stackTraceElement) Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.withAttributeFilter
(Predicate<Attr> attributeFilter) Registers a filter for attributes.withComparisonController
(ComparisonController comparisonController) Replace theComparisonControllers.Default
with your own ComparisonController.withComparisonFormatter
(ComparisonFormatter formatter) Sets a non-default formatter for the differences found.withComparisonListeners
(ComparisonListener... comparisonListeners) Registers listeners that are notified of each comparison.withDifferenceEvaluator
(DifferenceEvaluator differenceEvaluator) Provide your own customDifferenceEvaluator
implementation.withDifferenceListeners
(ComparisonListener... comparisonListeners) Registers listeners that are notified of each comparison with outcome other thanComparisonResult.EQUAL
.withNamespaceContext
(Map<String, String> prefix2Uri) Establish a namespace context that will be used inComparison.Detail#getXPath
.withNodeFilter
(Predicate<Node> nodeFilter) Registers a filter for nodes.withNodeMatcher
(NodeMatcher nodeMatcher) Sets the strategy for selecting nodes to compare.Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, 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, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, describedAs
-
Method Details
-
withNodeMatcher
Sets the strategy for selecting nodes to compare.Example with
DefaultNodeMatcher
:.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
This overwrites any
NodeMatcher
set via earlier invocations ofwithNodeMatcher
.- Specified by:
withNodeMatcher
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
nodeMatcher
- the NodeMatcher to use- Returns:
- this
- See Also:
-
withDifferenceEvaluator
Provide your own customDifferenceEvaluator
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...)
orDifferenceEvaluators.first(DifferenceEvaluator...)
to combine them:.withDifferenceEvaluator( DifferenceEvaluators.chain( DifferenceEvaluators.Default, new MyCustomDifferenceEvaluator())) ....
This overwrites any
DifferenceEvaluator
set via earlier invocations ofwithDifferenceEvaluator
.- Specified by:
withDifferenceEvaluator
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
differenceEvaluator
- the DifferenceEvaluator to use- Returns:
- this
- See Also:
-
withComparisonController
Replace theComparisonControllers.Default
with your own ComparisonController.Example use:
.withComparisonController(ComparisonControllers.StopWhenDifferent)
This overwrites any
ComparisonController
set via earlier invocations ofwithComparisonController
.- Specified by:
withComparisonController
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
comparisonController
- ComparisonController to use- Returns:
- this
- See Also:
-
withComparisonListeners
Registers listeners that are notified of each comparison.- Specified by:
withComparisonListeners
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
comparisonListeners
- ComparisonListeners to use- Returns:
- this
- See Also:
-
withDifferenceListeners
Registers listeners that are notified of each comparison with outcome other thanComparisonResult.EQUAL
.This overwrites any
ComparisonListener
s set via earlier invocations ofwithDifferenceListeners
.- Specified by:
withDifferenceListeners
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
comparisonListeners
- ComparisonListeners to use- Returns:
- this
- See Also:
-
withNamespaceContext
Establish a namespace context that will be used inComparison.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 ofwithNamespaceContext
.- Specified by:
withNamespaceContext
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
prefix2Uri
- mapping between prefix and namespace URI- Returns:
- this
- See Also:
-
withAttributeFilter
Registers a filter for attributes.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 ofwithAttributeFilter
.- Specified by:
withAttributeFilter
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
attributeFilter
- attribute filter to use- Returns:
- this
- See Also:
-
withNodeFilter
Registers a filter for nodes.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 ofwithNodeFilter
.- Specified by:
withNodeFilter
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
nodeFilter
- node filter to use- Returns:
- this
- See Also:
-
withComparisonFormatter
Sets a non-default formatter for the differences found.This overwrites any
ComparisonFormatter
set via earlier invocations ofwithComparisonFormatter
.- Specified by:
withComparisonFormatter
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
formatter
- formatter to use- Returns:
- this
- See Also:
-
withDocumentBuilderFactory
- Parameters:
f
- the DocumentBuilderFactory to use- Returns:
- this
- See Also:
-
ignoreWhitespace
Ignore whitespace by removing all empty text nodes and trimming the non-empty ones.- Returns:
- this
- See Also:
-
normalizeWhitespace
Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.- Returns:
- this
- See Also:
-
ignoreElementContentWhitespace
Ignore element content whitespace by removing all text nodes solely consisting of whitespace.- Returns:
- this
- See Also:
-
ignoreComments
Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.- Returns:
- this
- See Also:
-
ignoreCommentsUsingXSLTVersion
Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.- Parameters:
xsltVersion
- use this version for the stylesheet- Returns:
- this
- See Also:
-
ignoreChildNodesOrder
Equivalent for.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) .withDifferenceEvaluator( chain( Default, DifferenceEvaluators.downgradeDifferencesToEqual(ComparisonType.CHILD_NODELIST_SEQUENCE)));
- Returns:
- this
- See Also:
-
areIdentical
Check if actual and control XMLs are identical. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenSimilar
is used.- Returns:
- this
- Throws:
AssertionError
- if the test value is invalidAssertionError
- if the control value is invalid- See Also:
-
areNotIdentical
Check if actual and control XMLs are not identical. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenSimilar
is used.- Returns:
- this
- Throws:
AssertionError
- if the test value is invalidAssertionError
- if the control value is invalid- See Also:
-
areSimilar
Check if actual and control XMLs are similar. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenDifferent
is used.- Returns:
- this
- Throws:
AssertionError
- if the test value is invalidAssertionError
- if the control value is invalid- See Also:
-
areNotSimilar
Check if actual and control XMLs are not similar. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenDifferent
is used.- Returns:
- this
- Throws:
AssertionError
- if the test value is invalidAssertionError
- if the control value is invalid- See Also:
-
isElementOfCustomAssert
- Overrides:
isElementOfCustomAssert
in classorg.assertj.core.api.AbstractAssert<SELF extends org.xmlunit.assertj3.CustomAbstractAssert<SELF,
ACTUAL>, ACTUAL>
-