Class CompareAssert

  • All Implemented Interfaces:
    org.assertj.core.api.Assert<CompareAssert,​java.lang.Object>, org.assertj.core.api.Descriptable<CompareAssert>, org.assertj.core.api.ExtensionPoints<CompareAssert,​java.lang.Object>, org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>

    public class CompareAssert
    extends org.assertj.core.api.AbstractAssert<SELF,​ACTUAL>
    implements org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
    Assertion methods for XMLs comparison.

    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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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​(java.lang.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​(java.lang.StackTraceElement stackTraceElement)  
      CompareAssert normalizeWhitespace()
      Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.
      CompareAssert withAttributeFilter​(org.xmlunit.util.Predicate<org.w3c.dom.Attr> attributeFilter)
      CompareAssert withComparisonController​(org.xmlunit.diff.ComparisonController comparisonController)
      CompareAssert withComparisonFormatter​(org.xmlunit.diff.ComparisonFormatter formatter)
      CompareAssert withComparisonListeners​(org.xmlunit.diff.ComparisonListener... comparisonListeners)
      CompareAssert withDifferenceEvaluator​(org.xmlunit.diff.DifferenceEvaluator differenceEvaluator)
      CompareAssert withDifferenceListeners​(org.xmlunit.diff.ComparisonListener... comparisonListeners)
      CompareAssert withDocumentBuilderFactory​(javax.xml.parsers.DocumentBuilderFactory f)
      Sets the DocumentBuilderFactory to use when creating a Document from the Sources to compare.
      CompareAssert withNamespaceContext​(java.util.Map<java.lang.String,​java.lang.String> prefix2Uri)
      CompareAssert withNodeFilter​(org.xmlunit.util.Predicate<org.w3c.dom.Node> nodeFilter)
      CompareAssert withNodeMatcher​(org.xmlunit.diff.NodeMatcher nodeMatcher)
      • Methods inherited from class org.assertj.core.api.AbstractAssert

        actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, 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, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, 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, as, describedAs, describedAs
    • Method Detail

      • withNodeMatcher

        public CompareAssert withNodeMatcher​(org.xmlunit.diff.NodeMatcher nodeMatcher)
        Specified by:
        withNodeMatcher in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withNodeMatcher(NodeMatcher)
      • withDifferenceEvaluator

        public CompareAssert withDifferenceEvaluator​(org.xmlunit.diff.DifferenceEvaluator differenceEvaluator)
        Specified by:
        withDifferenceEvaluator in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withDifferenceEvaluator(DifferenceEvaluator)
      • withComparisonController

        public CompareAssert withComparisonController​(org.xmlunit.diff.ComparisonController comparisonController)
        Specified by:
        withComparisonController in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withComparisonController(ComparisonController)
      • withComparisonListeners

        public CompareAssert withComparisonListeners​(org.xmlunit.diff.ComparisonListener... comparisonListeners)
        Specified by:
        withComparisonListeners in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withComparisonListeners(ComparisonListener...)
      • withDifferenceListeners

        public CompareAssert withDifferenceListeners​(org.xmlunit.diff.ComparisonListener... comparisonListeners)
        Specified by:
        withDifferenceListeners in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withDifferenceListeners(ComparisonListener...)
      • withNamespaceContext

        public CompareAssert withNamespaceContext​(java.util.Map<java.lang.String,​java.lang.String> prefix2Uri)
        Specified by:
        withNamespaceContext in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withNamespaceContext(Map)
      • withAttributeFilter

        public CompareAssert withAttributeFilter​(org.xmlunit.util.Predicate<org.w3c.dom.Attr> attributeFilter)
        Specified by:
        withAttributeFilter in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withAttributeFilter(Predicate)
      • withNodeFilter

        public CompareAssert withNodeFilter​(org.xmlunit.util.Predicate<org.w3c.dom.Node> nodeFilter)
        Specified by:
        withNodeFilter in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withNodeFilter(Predicate)
      • withComparisonFormatter

        public CompareAssert withComparisonFormatter​(org.xmlunit.diff.ComparisonFormatter formatter)
        Specified by:
        withComparisonFormatter in interface org.xmlunit.builder.DifferenceEngineConfigurer<CompareAssert>
        See Also:
        DiffBuilder.withComparisonFormatter(ComparisonFormatter)
      • withDocumentBuilderFactory

        public CompareAssert withDocumentBuilderFactory​(javax.xml.parsers.DocumentBuilderFactory f)
        Sets the DocumentBuilderFactory to use when creating a Document from the Sources to compare.
        Parameters:
        f - the DocumentBuilderFactory to use
        Returns:
        this
        See Also:
        DiffBuilder.withDocumentBuilderFactory(DocumentBuilderFactory)
      • ignoreWhitespace

        public CompareAssert ignoreWhitespace()
        Ignore whitespace by removing all empty text nodes and trimming the non-empty ones.
        Returns:
        this
        See Also:
        DiffBuilder.ignoreWhitespace()
      • normalizeWhitespace

        public CompareAssert normalizeWhitespace()
        Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.
        Returns:
        this
        See Also:
        DiffBuilder.normalizeWhitespace()
      • ignoreElementContentWhitespace

        public CompareAssert ignoreElementContentWhitespace()
        Ignore element content whitespace by removing all text nodes solely consisting of whitespace.
        Returns:
        this
        See Also:
        DiffBuilder.ignoreElementContentWhitespace()
      • ignoreComments

        public CompareAssert ignoreComments()
        Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.
        Returns:
        this
        See Also:
        DiffBuilder.ignoreComments()
      • ignoreCommentsUsingXSLTVersion

        public CompareAssert ignoreCommentsUsingXSLTVersion​(java.lang.String xsltVersion)
        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:
        DiffBuilder.ignoreCommentsUsingXSLTVersion(String)
      • ignoreChildNodesOrder

        public CompareAssert ignoreChildNodesOrder()
        Equivalent for
             .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
             .withDifferenceEvaluator(
                  chain(
                      Default,
                      DifferenceEvaluators.downgradeDifferencesToEqual(ComparisonType.CHILD_NODELIST_SEQUENCE)));
         
        Returns:
        this
        See Also:
        DiffBuilder.withNodeMatcher(NodeMatcher)
      • areIdentical

        public CompareAssert areIdentical()
        Check if actual and control XMLs are identical. If custom comparison controller wasn't defined then ComparisonControllers.StopWhenSimilar is used.
        Returns:
        this
        Throws:
        java.lang.AssertionError - if the test value is invalid
        java.lang.AssertionError - if the control value is invalid
        See Also:
        DiffBuilder.checkForIdentical()
      • areNotIdentical

        public CompareAssert areNotIdentical()
        Check if actual and control XMLs are not identical. If custom comparison controller wasn't defined then ComparisonControllers.StopWhenSimilar is used.
        Returns:
        this
        Throws:
        java.lang.AssertionError - if the test value is invalid
        java.lang.AssertionError - if the control value is invalid
        See Also:
        DiffBuilder.checkForSimilar()
      • areSimilar

        public CompareAssert areSimilar()
        Check if actual and control XMLs are similar. If custom comparison controller wasn't defined then ComparisonControllers.StopWhenDifferent is used.
        Returns:
        this
        Throws:
        java.lang.AssertionError - if the test value is invalid
        java.lang.AssertionError - if the control value is invalid
        See Also:
        DiffBuilder.checkForSimilar()
      • areNotSimilar

        public CompareAssert areNotSimilar()
        Check if actual and control XMLs are not similar. If custom comparison controller wasn't defined then ComparisonControllers.StopWhenDifferent is used.
        Returns:
        this
        Throws:
        java.lang.AssertionError - if the test value is invalid
        java.lang.AssertionError - if the control value is invalid
        See Also:
        DiffBuilder.checkForSimilar()
      • isElementOfCustomAssert

        protected boolean isElementOfCustomAssert​(java.lang.StackTraceElement stackTraceElement)
        Overrides:
        isElementOfCustomAssert in class org.assertj.core.api.AbstractAssert<SELF extends org.xmlunit.assertj3.CustomAbstractAssert<SELF,​ACTUAL>,​ACTUAL>