Package org.xmlunit.placeholder
Class PlaceholderDifferenceEvaluator
java.lang.Object
org.xmlunit.placeholder.PlaceholderDifferenceEvaluator
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionstatic final String
Pattern used to find then end of an argument list.static final String
Pattern used to find the start of an argument list.static final String
Pattern used to find an argument separator.static final String
Pattern used to find the end of a placeholder.static final String
Pattern used to find the start of a placeholder. -
Constructor Summary
ConstructorDescriptionCreates a PlaceholderDifferenceEvaluator with default delimitersPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
andPLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
.PlaceholderDifferenceEvaluator
(String placeholderOpeningDelimiterRegex, String placeholderClosingDelimiterRegex) Creates a PlaceholderDifferenceEvaluator with custom delimiters.PlaceholderDifferenceEvaluator
(String placeholderOpeningDelimiterRegex, String placeholderClosingDelimiterRegex, String placeholderArgsOpeningDelimiterRegex, String placeholderArgsClosingDelimiterRegex, String placeholderArgsSeparatorRegex) Creates a PlaceholderDifferenceEvaluator with custom delimiters. -
Method Summary
Modifier and TypeMethodDescriptionevaluate
(Comparison comparison, ComparisonResult outcome) May alter the outcome of a comparison.
-
Field Details
-
PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
Pattern used to find the start of a placeholder. -
PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
Pattern used to find the end of a placeholder. -
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
Pattern used to find then end of an argument list.- Since:
- 2.7.0
-
PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX
Pattern used to find an argument separator.- Since:
- 2.7.0
-
-
Constructor Details
-
PlaceholderDifferenceEvaluator
public PlaceholderDifferenceEvaluator()Creates a PlaceholderDifferenceEvaluator with default delimitersPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
andPLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
. -
PlaceholderDifferenceEvaluator
public PlaceholderDifferenceEvaluator(String placeholderOpeningDelimiterRegex, String placeholderClosingDelimiterRegex) Creates a PlaceholderDifferenceEvaluator with custom delimiters.- Parameters:
placeholderOpeningDelimiterRegex
- regular expression for the opening delimiter of placeholder, defaults toPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
if the parameter is null or blankplaceholderClosingDelimiterRegex
- regular expression for the closing delimiter of placeholder, defaults toPLACEHOLDER_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 toPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
if the parameter is null or blankplaceholderClosingDelimiterRegex
- regular expression for the closing delimiter of placeholder, defaults toPLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
if the parameter is null or blankplaceholderArgsOpeningDelimiterRegex
- regular expression for the opening delimiter of the placeholder's argument list, defaults toPLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX
if the parameter is null or blankplaceholderArgsClosingDelimiterRegex
- regular expression for the closing delimiter of the placeholder's argument list, defaults toPLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX
if the parameter is null or blankplaceholderArgsSeparatorRegex
- regular expression for the delimiter between arguments inside of the placeholder's argument list, defaults toPLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX
if the parameter is null or blank- Since:
- 2.7.0
-
-
Method Details
-
evaluate
Description copied from interface:DifferenceEvaluator
May alter the outcome of a comparison.- Specified by:
evaluate
in interfaceDifferenceEvaluator
- Parameters:
comparison
- the comparisonoutcome
- the current outcome of the comparison- Returns:
- the new result of the comparison.
-