Class AbstractJsonContentAssert<SELF extends AbstractJsonContentAssert<SELF>>

java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
org.assertj.core.api.AbstractObjectAssert<SELF,JsonContent>
org.springframework.test.json.AbstractJsonContentAssert<SELF>
Type Parameters:
SELF - the type of assertions
All Implemented Interfaces:
org.assertj.core.api.Assert<SELF,JsonContent>, org.assertj.core.api.Descriptable<SELF>, org.assertj.core.api.ExtensionPoints<SELF,JsonContent>
Direct Known Subclasses:
JsonContentAssert

public abstract class AbstractJsonContentAssert<SELF extends AbstractJsonContentAssert<SELF>> extends org.assertj.core.api.AbstractObjectAssert<SELF,JsonContent>
Base AssertJ assertions that can be applied to a JSON document.

Supports evaluating JSON path expressions and extracting a part of the document for further assertions on the value.

Also supports comparing the JSON document against a target, using a JSON Comparator. Resources that are loaded from the classpath can be relative if a class is provided. By default, UTF-8 is used to load resources, but this can be overridden using withCharset(Charset).

Since:
6.2
Author:
Stephane Nicoll, Phillip Webb, Andy Wilkinson, Diego Berrueta, Camille Vienot
  • Field Summary

    Fields inherited from class org.assertj.core.api.AbstractAssert

    actual, info, myself, objects, throwUnsupportedExceptionOnEquals
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Create an assert for the given JSON document.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> org.assertj.core.api.AbstractObjectAssert<?,T>
    convertTo(Class<T> target)
    Verify that the actual value can be converted to an instance of the given target, and produce a new assertion object narrowed to that type.
    <ASSERT extends org.assertj.core.api.AbstractAssert<?, ?>>
    ASSERT
    convertTo(org.assertj.core.api.AssertFactory<?,ASSERT> assertFactory)
    Verify that the actual value can be converted to an instance of the type defined by the given AssertFactory and return a new Assert narrowed to that type.
    Verify that the given JSON path does not match.
    Verify that the given JSON path is present, and extract the JSON value for further assertions.
    Verify that the given JSON path matches.
    hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements)
    Verify that the given JSON path is present with a JSON value satisfying the given valueRequirements.
    Verify that the actual value is strictly equal to the given JSON.
    isEqualTo(CharSequence expected, JsonComparator comparator)
    Verify that the actual value is equal to the given JSON.
    isEqualTo(CharSequence expected, JsonCompareMode compareMode)
    Verify that the actual value is equal to the given JSON.
    isEqualTo(Resource expected, JsonComparator comparator)
    Verify that the actual value is equal to the given JSON Resource.
    isEqualTo(Resource expected, JsonCompareMode compareMode)
    Verify that the actual value is equal to the given JSON Resource.
    Verify that the actual value is leniently equal to the given JSON.
    Verify that the actual value is leniently equal to the given JSON Resource.
    Verify that the actual value is strictly not equal to the given JSON.
    isNotEqualTo(CharSequence expected, JsonComparator comparator)
    Verify that the actual value is not equal to the given JSON.
    isNotEqualTo(CharSequence expected, JsonCompareMode compareMode)
    Verify that the actual value is not equal to the given JSON.
    isNotEqualTo(Resource expected, JsonComparator comparator)
    Verify that the actual value is not equal to the given JSON Resource.
    isNotEqualTo(Resource expected, JsonCompareMode compareMode)
    Verify that the actual value is not equal to the given JSON Resource.
    Verify that the actual value is not leniently equal to the given JSON.
    Verify that the actual value is not leniently equal to the given JSON Resource.
    Verify that the actual value is not strictly equal to the given JSON.
    Verify that the actual value is not strictly equal to the given JSON Resource.
    Verify that the actual value is strictly equal to the given JSON.
    Verify that the actual value is strictly equal to the given JSON Resource.
    Override the Charset to use to load resources.
    withResourceLoadClass(Class<?> resourceLoadClass)
    Override the class used to load resources.

    Methods inherited from class org.assertj.core.api.AbstractObjectAssert

    as, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison

    Methods inherited from class org.assertj.core.api.AbstractAssert

    areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.assertj.core.api.Descriptable

    as, describedAs, describedAs
  • Constructor Details

    • AbstractJsonContentAssert

      protected AbstractJsonContentAssert(@Nullable JsonContent actual, Class<?> selfType)
      Create an assert for the given JSON document.
      Parameters:
      actual - the JSON document to assert
      selfType - the implementation type of this assert
  • Method Details

    • convertTo

      public <T> org.assertj.core.api.AbstractObjectAssert<?,T> convertTo(Class<T> target)
      Verify that the actual value can be converted to an instance of the given target, and produce a new assertion object narrowed to that type.
      Parameters:
      target - the type to convert the actual value to
    • convertTo

      public <ASSERT extends org.assertj.core.api.AbstractAssert<?, ?>> ASSERT convertTo(org.assertj.core.api.AssertFactory<?,ASSERT> assertFactory)
      Verify that the actual value can be converted to an instance of the type defined by the given AssertFactory and return a new Assert narrowed to that type.

      InstanceOfAssertFactories provides static factories for all the types supported by Assertions.assertThat(java.util.function.Predicate<T>). Additional factories can be created by implementing AssertFactory.

      Example:

      
       // Check that the JSON document is an array of 3 users
       assertThat(json).convertTo(InstanceOfAssertFactories.list(User.class))
               hasSize(3); // ListAssert of User
       
      Parameters:
      assertFactory - the AssertFactory to use to produce a narrowed Assert for the type that it defines.
    • extractingPath

      public JsonPathValueAssert extractingPath(String path)
      Verify that the given JSON path is present, and extract the JSON value for further assertions.
      Parameters:
      path - the JsonPath expression
      See Also:
    • hasPathSatisfying

      public SELF hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements)
      Verify that the given JSON path is present with a JSON value satisfying the given valueRequirements.
      Parameters:
      path - the JsonPath expression
      valueRequirements - a Consumer of the assertion object
    • hasPath

      public SELF hasPath(String path)
      Verify that the given JSON path matches. For paths with an operator, this validates that the path expression is valid, but does not validate that it yield any results.
      Parameters:
      path - the JsonPath expression
    • doesNotHavePath

      public SELF doesNotHavePath(String path)
      Verify that the given JSON path does not match.
      Parameters:
      path - the JsonPath expression
    • isEqualTo

      public SELF isEqualTo(@Nullable CharSequence expected)
      Verify that the actual value is strictly equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
      See Also:
    • isEqualTo

      public SELF isEqualTo(@Nullable CharSequence expected, JsonCompareMode compareMode)
      Verify that the actual value is equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
      compareMode - the compare mode used when checking
    • isEqualTo

      public SELF isEqualTo(Resource expected, JsonCompareMode compareMode)
      Verify that the actual value is equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
      compareMode - the compare mode used when checking
    • isEqualTo

      public SELF isEqualTo(@Nullable CharSequence expected, JsonComparator comparator)
      Verify that the actual value is equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
      comparator - the comparator used when checking
    • isEqualTo

      public SELF isEqualTo(Resource expected, JsonComparator comparator)
      Verify that the actual value is equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
      comparator - the comparator used when checking
    • isLenientlyEqualTo

      public SELF isLenientlyEqualTo(@Nullable CharSequence expected)
      Verify that the actual value is leniently equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
    • isLenientlyEqualTo

      public SELF isLenientlyEqualTo(Resource expected)
      Verify that the actual value is leniently equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
    • isStrictlyEqualTo

      public SELF isStrictlyEqualTo(@Nullable CharSequence expected)
      Verify that the actual value is strictly equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
    • isStrictlyEqualTo

      public SELF isStrictlyEqualTo(Resource expected)
      Verify that the actual value is strictly equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
    • isNotEqualTo

      public SELF isNotEqualTo(@Nullable CharSequence expected)
      Verify that the actual value is strictly not equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
      See Also:
    • isNotEqualTo

      public SELF isNotEqualTo(@Nullable CharSequence expected, JsonCompareMode compareMode)
      Verify that the actual value is not equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
      compareMode - the compare mode used when checking
    • isNotEqualTo

      public SELF isNotEqualTo(Resource expected, JsonCompareMode compareMode)
      Verify that the actual value is not equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
      compareMode - the compare mode used when checking
    • isNotEqualTo

      public SELF isNotEqualTo(@Nullable CharSequence expected, JsonComparator comparator)
      Verify that the actual value is not equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
      comparator - the comparator used when checking
    • isNotEqualTo

      public SELF isNotEqualTo(Resource expected, JsonComparator comparator)
      Verify that the actual value is not equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
      comparator - the comparator used when checking
    • isNotLenientlyEqualTo

      public SELF isNotLenientlyEqualTo(@Nullable CharSequence expected)
      Verify that the actual value is not leniently equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
    • isNotLenientlyEqualTo

      public SELF isNotLenientlyEqualTo(Resource expected)
      Verify that the actual value is not leniently equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
    • isNotStrictlyEqualTo

      public SELF isNotStrictlyEqualTo(@Nullable CharSequence expected)
      Verify that the actual value is not strictly equal to the given JSON. The expected value can contain the JSON itself or, if it ends with .json, the name of a resource to be loaded from the classpath.
      Parameters:
      expected - the expected JSON or the name of a resource containing the expected JSON
    • isNotStrictlyEqualTo

      public SELF isNotStrictlyEqualTo(Resource expected)
      Verify that the actual value is not strictly equal to the given JSON Resource.

      The resource abstraction allows to provide several input types:

      Parameters:
      expected - a resource containing the expected JSON
    • withResourceLoadClass

      public SELF withResourceLoadClass(@Nullable Class<?> resourceLoadClass)
      Override the class used to load resources.

      Resources can be loaded from an absolute location or relative to the specified class. For instance, specifying com.example.MyClass as the resource class allows you to use "my-file.json" to load /com/example/my-file.json.

      Parameters:
      resourceLoadClass - the class used to load resources, or null to only use absolute paths
    • withCharset

      public SELF withCharset(@Nullable Charset charset)
      Override the Charset to use to load resources.

      By default, resources are loaded using UTF-8.

      Parameters:
      charset - the charset to use, or null to use the default