Class PlaceholderDifferenceEvaluator

  • All Implemented Interfaces:
    DifferenceEvaluator

    public class PlaceholderDifferenceEvaluator
    extends Object
    implements DifferenceEvaluator
    This class is used to add placeholder feature to XML comparison.

    This class and the whole module are considered experimental and any API may change between releases of XMLUnit.

    To use it, just add it with DiffBuilder like below

     Diff diff = DiffBuilder.compare(control).withTest(test).withDifferenceEvaluator(new PlaceholderDifferenceEvaluator()).build();
     

    Supported scenarios are demonstrated in the unit tests (PlaceholderDifferenceEvaluatorTest).

    Default delimiters for placeholder are ${ and }. Arguments to placeholders are by default enclosed in ( and ) and separated by , - whitespace is significant, arguments are not quoted.

    To use custom delimiters (in regular expression), create instance with the PlaceholderDifferenceEvaluator(String, String) or PlaceholderDifferenceEvaluator(String, String, String, String, String) constructors.

    Since:
    2.6.0
    • Field Detail

      • PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX

        public static final String PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
        Pattern used to find the start of a placeholder.
      • PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX

        public static final String PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
        Pattern used to find the end of a placeholder.
      • PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX

        public static final String PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX
        Pattern used to find the start of an argument list.
        Since:
        2.7.0
      • PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX

        public static final String PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX
        Pattern used to find then end of an argument list.
        Since:
        2.7.0
      • PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX

        public static final String PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX
        Pattern used to find an argument separator.
        Since:
        2.7.0
    • Constructor Detail

      • PlaceholderDifferenceEvaluator

        public PlaceholderDifferenceEvaluator​(String placeholderOpeningDelimiterRegex,
                                              String placeholderClosingDelimiterRegex)
        Creates a PlaceholderDifferenceEvaluator with custom delimiters.
        Parameters:
        placeholderOpeningDelimiterRegex - regular expression for the opening delimiter of placeholder, defaults to PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX if the parameter is null or blank
        placeholderClosingDelimiterRegex - regular expression for the closing delimiter of placeholder, defaults to PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX if the parameter is null or blank
      • PlaceholderDifferenceEvaluator

        public PlaceholderDifferenceEvaluator​(String placeholderOpeningDelimiterRegex,
                                              String placeholderClosingDelimiterRegex,
                                              String placeholderArgsOpeningDelimiterRegex,
                                              String placeholderArgsClosingDelimiterRegex,
                                              String placeholderArgsSeparatorRegex)
        Creates a PlaceholderDifferenceEvaluator with custom delimiters.
        Parameters:
        placeholderOpeningDelimiterRegex - regular expression for the opening delimiter of placeholder, defaults to PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX if the parameter is null or blank
        placeholderClosingDelimiterRegex - regular expression for the closing delimiter of placeholder, defaults to PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX if the parameter is null or blank
        placeholderArgsOpeningDelimiterRegex - regular expression for the opening delimiter of the placeholder's argument list, defaults to PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX if the parameter is null or blank
        placeholderArgsClosingDelimiterRegex - regular expression for the closing delimiter of the placeholder's argument list, defaults to PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX if the parameter is null or blank
        placeholderArgsSeparatorRegex - regular expression for the delimiter between arguments inside of the placeholder's argument list, defaults to PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX if the parameter is null or blank
        Since:
        2.7.0