Class AbstractJsonContentAssert<SELF extends 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
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
ConstructorsModifierConstructorDescriptionprotectedAbstractJsonContentAssert(@Nullable JsonContent actual, Class<?> selfType) Create an assert for the given JSON document. -
Method Summary
Modifier and TypeMethodDescription<T> org.assertj.core.api.AbstractObjectAssert<?, T> Verify that the actual value can be converted to an instance of the giventarget, and produce a new assertion object narrowed to that type.<ASSERT extends org.assertj.core.api.AbstractAssert<?,?>>
ASSERTconvertTo(org.assertj.core.api.AssertFactory<?, ASSERT> assertFactory) Verify that the actual value can be converted to an instance of the type defined by the givenAssertFactoryand return a new Assert narrowed to that type.doesNotHavePath(String path) Verify that the given JSONpathdoes not match.extractingPath(String path) Verify that the given JSONpathis present, and extract the JSON value for further assertions.Verify that the given JSONpathmatches.hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpathis present with a JSON value satisfying the givenvalueRequirements.isEqualTo(@Nullable CharSequence expected) Verify that the actual value is strictly equal to the given JSON.isEqualTo(@Nullable CharSequence expected, JsonComparator comparator) Verify that the actual value is equal to the given JSON.isEqualTo(@Nullable 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 JSONResource.isEqualTo(Resource expected, JsonCompareMode compareMode) Verify that the actual value is equal to the given JSONResource.isLenientlyEqualTo(@Nullable CharSequence expected) Verify that the actual value islenientlyequal to the given JSON.isLenientlyEqualTo(Resource expected) isNotEqualTo(@Nullable CharSequence expected) Verify that the actual value is strictly not equal to the given JSON.isNotEqualTo(@Nullable CharSequence expected, JsonComparator comparator) Verify that the actual value is not equal to the given JSON.isNotEqualTo(@Nullable 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 JSONResource.isNotEqualTo(Resource expected, JsonCompareMode compareMode) Verify that the actual value is not equal to the given JSONResource.isNotLenientlyEqualTo(@Nullable CharSequence expected) Verify that the actual value is notlenientlyequal to the given JSON.isNotLenientlyEqualTo(Resource expected) isNotStrictlyEqualTo(@Nullable CharSequence expected) Verify that the actual value is notstrictlyequal to the given JSON.isNotStrictlyEqualTo(Resource expected) isStrictlyEqualTo(@Nullable CharSequence expected) Verify that the actual value isstrictlyequal to the given JSON.isStrictlyEqualTo(Resource expected) withCharset(@Nullable Charset charset) Override theCharsetto use to load resources.withResourceLoadClass(@Nullable 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, usingRecursiveComparisonMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, 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, usingEquals, usingEquals, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, describedAs, describedAs
-
Constructor Details
-
AbstractJsonContentAssert
Create an assert for the given JSON document.- Parameters:
actual- the JSON document to assertselfType- the implementation type of this assert
-
-
Method Details
-
convertTo
-
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 givenAssertFactoryand return a new Assert narrowed to that type.InstanceOfAssertFactoriesprovides static factories for all the types supported byAssertions.assertThat(Predicate). Additional factories can be created by implementingAssertFactory.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- theAssertFactoryto use to produce a narrowed Assert for the type that it defines.
-
extractingPath
Verify that the given JSONpathis present, and extract the JSON value for further assertions.- Parameters:
path- theJsonPathexpression- See Also:
-
hasPathSatisfying
public SELF hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpathis present with a JSON value satisfying the givenvalueRequirements.- Parameters:
path- theJsonPathexpressionvalueRequirements- aConsumerof the assertion object
-
hasPath
-
doesNotHavePath
-
isEqualTo
Verify that the actual value is strictly equal to the given JSON. Theexpectedvalue 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
Verify that the actual value is equal to the given JSON. Theexpectedvalue 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 JSONcompareMode- the compare mode used when checking
-
isEqualTo
Verify that the actual value is equal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSONcompareMode- the compare mode used when checking
- a
-
isEqualTo
Verify that the actual value is equal to the given JSON. Theexpectedvalue 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 JSONcomparator- the comparator used when checking
-
isEqualTo
Verify that the actual value is equal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSONcomparator- the comparator used when checking
- a
-
isLenientlyEqualTo
Verify that the actual value islenientlyequal to the given JSON. Theexpectedvalue 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
Verify that the actual value islenientlyequal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSON
- a
-
isStrictlyEqualTo
Verify that the actual value isstrictlyequal to the given JSON. Theexpectedvalue 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
Verify that the actual value isstrictlyequal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSON
- a
-
isNotEqualTo
Verify that the actual value is strictly not equal to the given JSON. Theexpectedvalue 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
Verify that the actual value is not equal to the given JSON. Theexpectedvalue 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 JSONcompareMode- the compare mode used when checking
-
isNotEqualTo
Verify that the actual value is not equal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSONcompareMode- the compare mode used when checking
- a
-
isNotEqualTo
Verify that the actual value is not equal to the given JSON. Theexpectedvalue 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 JSONcomparator- the comparator used when checking
-
isNotEqualTo
Verify that the actual value is not equal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSONcomparator- the comparator used when checking
- a
-
isNotLenientlyEqualTo
Verify that the actual value is notlenientlyequal to the given JSON. Theexpectedvalue 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
Verify that the actual value is notlenientlyequal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSON
- a
-
isNotStrictlyEqualTo
Verify that the actual value is notstrictlyequal to the given JSON. Theexpectedvalue 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
Verify that the actual value is notstrictlyequal to the given JSONResource.The resource abstraction allows to provide several input types:
- a
bytearray, usingByteArrayResource - a
classpathresource, usingClassPathResource - a
FileorPath, usingFileSystemResource - an
InputStream, usingInputStreamResource
- Parameters:
expected- a resource containing the expected JSON
- a
-
withResourceLoadClass
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.MyClassas 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, ornullto only use absolute paths
-
withCharset
-