Class InternalMatcher
java.lang.Object
net.javacrumbs.jsonunit.core.internal.matchers.InternalMatcher
public final class InternalMatcher extends Object
Internal class, please do not use outside the library
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classInternalMatcher.ArrayMatcherArray assertions -
Field Summary
-
Constructor Summary
Constructors Constructor Description InternalMatcher(@Nullable Object actual, @NotNull Path path, @NotNull String description, @NotNull Configuration configuration) -
Method Summary
Modifier and Type Method Description @NotNull NodeassertIntegralNumber()@NotNull NodeassertType(Node.NodeType type)@NotNull InternalMatcherdescribedAs(@NotNull String description)Sets the description of this object.voidfailOnType(@NotNull Node node, @NotNull String expectedType)voidhasSameStructureAs(@Nullable Object expected)Compares JSON structure.voidisAbsent()Fails if the node exists.@NotNull InternalMatcher.ArrayMatcherisArray()Fails if the selected JSON is not an Array or is not present.voidisEqualTo(@Nullable Object expected)voidisNotEqualTo(@Nullable Object expected)Fails if compared documents are equal.voidisNotNull()voidisNull()voidisObject()Fails if the selected JSON is not an Object or is not present.voidisPresent()Fails if the node is missing.voidisPresent(@Nullable String expectedValue)voidisString()Fails if the selected JSON is not a String or is not present.voidisStringEqualTo(@Nullable String expected)Fails if the selected JSON is not a String or is not present or the value is not equal to expected value.voidmatches(@NotNull org.hamcrest.Matcher<?> matcher)Matches the node using Hamcrest matcher.@NotNull InternalMatchernode(@NotNull String newPath)Creates an assert object that only compares given node.@NotNull InternalMatcherwhen(@NotNull ConfigurationWhen.PathsParam object, @NotNull ConfigurationWhen.ApplicableForPath... actions)Sets advanced/local options.@NotNull InternalMatcherwhenIgnoringPaths(@NotNull String... pathsToBeIgnored)@NotNull InternalMatcherwithDifferenceListener(@NotNull DifferenceListener differenceListener)@NotNull InternalMatcherwithIgnorePlaceholder(@NotNull String ignorePlaceholder)Sets the placeholder that can be used to ignore values.@NotNull InternalMatcherwithMatcher(@NotNull String matcherName, @NotNull org.hamcrest.Matcher<?> matcher)Adds a internalMatcher to be used in ${json-unit.matches:matcherName} macro.@NotNull InternalMatcherwithOptions(@NotNull Option firstOption, @NotNull Option... otherOptions)Sets options changing comparison behavior.@NotNull InternalMatcherwithTolerance(double tolerance)Sets the tolerance for floating number comparison.@NotNull InternalMatcherwithTolerance(@Nullable BigDecimal tolerance)Sets the tolerance for floating number comparison.
-
Field Details
-
ACTUAL
- See Also:
- Constant Field Values
-
-
Constructor Details
-
InternalMatcher
public InternalMatcher(@Nullable @Nullable Object actual, @NotNull @NotNull Path path, @NotNull @NotNull String description, @NotNull @NotNull Configuration configuration)
-
-
Method Details
-
whenIgnoringPaths
@NotNull public @NotNull InternalMatcher whenIgnoringPaths(@NotNull @NotNull String... pathsToBeIgnored) -
describedAs
Sets the description of this object. -
withIgnorePlaceholder
@NotNull public @NotNull InternalMatcher withIgnorePlaceholder(@NotNull @NotNull String ignorePlaceholder)Sets the placeholder that can be used to ignore values. The default value is ${json-unit.ignore} -
withTolerance
Sets the tolerance for floating number comparison. If set to null, requires exact match of the values. For example, if set to 0.01, ignores all differences lower than 0.01, so 1 and 0.9999 are considered equal. -
withTolerance
Sets the tolerance for floating number comparison. If set to null, requires exact match of the values. For example, if set to 0.01, ignores all differences lower than 0.01, so 1 and 0.9999 are considered equal. -
withMatcher
@NotNull public @NotNull InternalMatcher withMatcher(@NotNull @NotNull String matcherName, @NotNull @NotNull org.hamcrest.Matcher<?> matcher)Adds a internalMatcher to be used in ${json-unit.matches:matcherName} macro. -
withDifferenceListener
@NotNull public @NotNull InternalMatcher withDifferenceListener(@NotNull @NotNull DifferenceListener differenceListener) -
withOptions
@NotNull public @NotNull InternalMatcher withOptions(@NotNull @NotNull Option firstOption, @NotNull @NotNull Option... otherOptions)Sets options changing comparison behavior. This method has to be called before assertion. For more info seeOption- Parameters:
firstOption-otherOptions-- See Also:
Option
-
when
@NotNull public final @NotNull InternalMatcher when(@NotNull @NotNull ConfigurationWhen.PathsParam object, @NotNull @NotNull ConfigurationWhen.ApplicableForPath... actions)Sets advanced/local options. This method has to be called before assertion. For more info seeConfiguration.when(PathsParam, ApplicableForPath...)- Parameters:
object-actions-- See Also:
Configuration.when(PathsParam, ApplicableForPath...)
-
isEqualTo
-
isStringEqualTo
Fails if the selected JSON is not a String or is not present or the value is not equal to expected value. -
isNotEqualTo
Fails if compared documents are equal. The expected object is converted to JSON before comparison. Ignores order of sibling nodes and whitespaces. -
hasSameStructureAs
Compares JSON structure. Ignores values, only compares shape of the document and key names. Is too lenient, ignores types, prefer IGNORING_VALUES option instead.- Parameters:
expected-
-
node
Creates an assert object that only compares given node. The path is denoted by JSON path, for example.assertThatJson("{\"root\":{\"test\":[1,2,3]}}").node("root.test[0]").isEqualTo("1");- Parameters:
newPath-
-
isAbsent
public void isAbsent()Fails if the node exists. -
isPresent
public void isPresent()Fails if the node is missing. -
isPresent
-
isArray
Fails if the selected JSON is not an Array or is not present. -
assertType
-
assertIntegralNumber
-
isObject
public void isObject()Fails if the selected JSON is not an Object or is not present. -
isString
public void isString()Fails if the selected JSON is not a String or is not present. -
isNull
public void isNull() -
isNotNull
public void isNotNull() -
failOnType
-
matches
public void matches(@NotNull @NotNull org.hamcrest.Matcher<?> matcher)Matches the node using Hamcrest matcher.- Numbers are mapped to BigDecimal
- Arrays are mapped to a Collection
- Objects are mapped to a map so you can use json(Part)Equals or a Map matcher
-