Class InternalMatcher


  • public final class InternalMatcher
    extends Object
    Internal class, please do not use outside the library
    • Method Detail

      • describedAs

        public InternalMatcher describedAs​(String description)
        Sets the description of this object.
      • withIgnorePlaceholder

        public InternalMatcher withIgnorePlaceholder​(String ignorePlaceholder)
        Sets the placeholder that can be used to ignore values. The default value is ${json-unit.ignore}
      • withTolerance

        public InternalMatcher withTolerance​(double tolerance)
        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

        public InternalMatcher withTolerance​(BigDecimal tolerance)
        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

        public InternalMatcher withMatcher​(String matcherName,
                                           org.hamcrest.Matcher<?> matcher)
        Adds a internalMatcher to be used in ${json-unit.matches:matcherName} macro.
      • withOptions

        public InternalMatcher withOptions​(Option firstOption,
                                           Option... otherOptions)
        Sets options changing comparison behavior. This method has to be called before assertion. For more info see Option
        Parameters:
        firstOption -
        otherOptions -
        See Also:
        Option
      • isEqualTo

        public void isEqualTo​(Object expected)
      • isStringEqualTo

        public void isStringEqualTo​(String expected)
        Fails if the selected JSON is not a String or is not present or the value is not equal to expected value.
      • isNotEqualTo

        public void isNotEqualTo​(Object expected)
        Fails if compared documents are equal. The expected object is converted to JSON before comparison. Ignores order of sibling nodes and whitespaces.
        Parameters:
        expected -
      • hasSameStructureAs

        public void hasSameStructureAs​(Object expected)
        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

        public InternalMatcher node​(String newPath)
        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 -
        Returns:
        object comparing only node given by path.
      • isAbsent

        public void isAbsent()
        Fails if the node exists.
      • isPresent

        public void isPresent()
        Fails if the node is missing.
      • isPresent

        public void isPresent​(String expectedValue)
      • 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

        public void failOnType​(Node node,
                               String expectedType)
      • matches

        public void matches​(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
        Parameters:
        matcher -