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
ModifierConstructorDescriptionprotected
AbstractJsonContentAssert
(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 givenAssertFactory
and return a new Assert narrowed to that type.doesNotHavePath
(String path) Verify that the given JSONpath
does not match.extractingPath
(String path) Verify that the given JSONpath
is present, and extract the JSON value for further assertions.Verify that the given JSONpath
matches.hasPathSatisfying
(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpath
is present with a JSON value satisfying the givenvalueRequirements
.isEqualTo
(CharSequence expected) 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 JSONResource
.isEqualTo
(Resource expected, JsonCompareMode compareMode) Verify that the actual value is equal to the given JSONResource
.isLenientlyEqualTo
(CharSequence expected) Verify that the actual value isleniently
equal to the given JSON.isLenientlyEqualTo
(Resource expected) isNotEqualTo
(CharSequence expected) 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 JSONResource
.isNotEqualTo
(Resource expected, JsonCompareMode compareMode) Verify that the actual value is not equal to the given JSONResource
.isNotLenientlyEqualTo
(CharSequence expected) Verify that the actual value is notleniently
equal to the given JSON.isNotLenientlyEqualTo
(Resource expected) isNotStrictlyEqualTo
(CharSequence expected) Verify that the actual value is notstrictly
equal to the given JSON.isNotStrictlyEqualTo
(Resource expected) isStrictlyEqualTo
(CharSequence expected) Verify that the actual value isstrictly
equal to the given JSON.isStrictlyEqualTo
(Resource expected) withCharset
(Charset charset) Override theCharset
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
Create an assert for the given JSON document.- Parameters:
actual
- the JSON document to assertselfType
- the implementation type of this assert
-
-
Method Details
-
convertTo
Verify that the actual value can be converted to an instance of the giventarget
, 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 givenAssertFactory
and return a new Assert narrowed to that type.InstanceOfAssertFactories
provides static factories for all the types supported byAssertions.assertThat(java.util.function.Predicate<T>)
. 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
- theAssertFactory
to use to produce a narrowed Assert for the type that it defines.
-
extractingPath
Verify that the given JSONpath
is present, and extract the JSON value for further assertions.- Parameters:
path
- theJsonPath
expression- See Also:
-
hasPathSatisfying
public SELF hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpath
is present with a JSON value satisfying the givenvalueRequirements
.- Parameters:
path
- theJsonPath
expressionvalueRequirements
- aConsumer
of the assertion object
-
hasPath
Verify that the given JSONpath
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
- theJsonPath
expression
-
doesNotHavePath
Verify that the given JSONpath
does not match.- Parameters:
path
- theJsonPath
expression
-
isEqualTo
Verify that the actual value is strictly equal to the given JSON. Theexpected
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
Verify that the actual value is equal to the given JSON. Theexpected
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 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
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, 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. Theexpected
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 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
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSONcomparator
- the comparator used when checking
- a
-
isLenientlyEqualTo
Verify that the actual value isleniently
equal to the given JSON. Theexpected
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
Verify that the actual value isleniently
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSON
- a
-
isStrictlyEqualTo
Verify that the actual value isstrictly
equal to the given JSON. Theexpected
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
Verify that the actual value isstrictly
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, 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. Theexpected
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
Verify that the actual value is not equal to the given JSON. Theexpected
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 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
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, 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. Theexpected
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 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
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, 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 notleniently
equal to the given JSON. Theexpected
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
Verify that the actual value is notleniently
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSON
- a
-
isNotStrictlyEqualTo
Verify that the actual value is notstrictly
equal to the given JSON. Theexpected
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
Verify that the actual value is notstrictly
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, 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.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, ornull
to only use absolute paths
-
withCharset
Override theCharset
to use to load resources.By default, resources are loaded using
UTF-8
.- Parameters:
charset
- the charset to use, ornull
to use the default
-