Package org.skyscreamer.jsonassert
Class RegularExpressionValueMatcher<T>
java.lang.Object
org.skyscreamer.jsonassert.RegularExpressionValueMatcher<T>
- Type Parameters:
T
- Generic Type
- All Implemented Interfaces:
ValueMatcher<T>
A JSONassert value matcher that matches actual value to regular expression.
If non-null regular expression passed to constructor, then all actual values
will be compared against this constant pattern, ignoring any expected value
passed to equal method. If null regular expression passed to constructor,
then expected value passed to equals method will be used to dynamically
specify regular expression pattern that actual value must match.
- Author:
- Duncan Mackinder
-
Constructor Summary
ConstructorDescriptionCreate RegularExpressionValueMatcher in which the pattern the actual value must match with be specified dynamically from the expected string passed to this matcher in the equals method.RegularExpressionValueMatcher
(String pattern) Create RegularExpressionValueMatcher with specified pattern. -
Method Summary
-
Constructor Details
-
RegularExpressionValueMatcher
public RegularExpressionValueMatcher()Create RegularExpressionValueMatcher in which the pattern the actual value must match with be specified dynamically from the expected string passed to this matcher in the equals method. -
RegularExpressionValueMatcher
Create RegularExpressionValueMatcher with specified pattern. If pattern is not null, it must be a valid regular expression that defines a constant expected pattern that every actual value must match (in this case the expected value passed to equal method will be ignored). If pattern is null, the pattern the actual value must match with be specified dynamically from the expected string passed to this matcher in the equals method.- Parameters:
pattern
- if non null, regular expression pattern which all actual values this matcher is applied to must match. If null, this matcher will apply pattern specified dynamically via the expected parameter to the equal method.- Throws:
IllegalArgumentException
- if pattern is non-null and not a valid regular expression.
-
-
Method Details
-
equal
Description copied from interface:ValueMatcher
Compares the two provided objects whether they are equal.- Specified by:
equal
in interfaceValueMatcher<T>
- Parameters:
actual
- the first object to checkexpected
- the object to check the first against- Returns:
- true if the objects are equal, false otherwise
-