Class JsonAssert
- All Implemented Interfaces:
org.assertj.core.api.Assert<JsonAssert, Object>, org.assertj.core.api.Descriptable<JsonAssert>, org.assertj.core.api.ExtensionPoints<JsonAssert, Object>
- Direct Known Subclasses:
JsonAssert.ConfigurableJsonAssert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classJsonAssert that can be configured to prevent mistakes likeassertThatJson(...).isEqualsTo(...).when(...); -
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Method Summary
Modifier and TypeMethodDescriptionand(JsonAssertion... assertions) Allows to do multiple comparisons on a document likeassertThatJson("{\"test\":{\"a\":1, \"b\":2, \"c\":3}}").and( a -> a.node("test").isObject(), a -> a.node("test.b").isEqualTo(3) );<ASSERT extends org.assertj.core.api.AbstractAssert<?,?>>
ASSERTasInstanceOf(org.assertj.core.api.InstanceOfAssertFactory<?, ASSERT> instanceOfAssertFactory) org.assertj.core.api.BigDecimalAssertasNumber()Asserts that given node is present and is of type number or a string that can be parsed as a number.org.assertj.core.api.AbstractStringAssert<?> asString()voidisAbsent()Asserts that given node is absent.isArray()Asserts that given node is present and is of type array.org.assertj.core.api.BooleanAssertAsserts that given node is present and is of type boolean.Compares JSONs.org.assertj.core.api.BigIntegerAssertAsserts that the value is an integer. 1 is an integer 1.0, 1.1, 1e3, 1e0, 1e-3 is not.Asserts that given node is present and is not null.voidisNull()Asserts that given node is present and is null.org.assertj.core.api.BigDecimalAssertisNumber()Asserts that given node is present and is of type number.isObject()Asserts that given node is present and is of type object.Asserts that given node is present.org.assertj.core.api.StringAssertisString()Asserts that given node is present and is of type string.org.assertj.core.api.StringAssertisStringEqualTo(String expected) Assert that the value is string and checks for equality.org.assertj.core.api.UriAssertisUri()Asserts that given node is present and is URI.Moves comparison to given node.Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asList, assertionError, 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, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotOfAnyClassIn, isNotSameAs, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, 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, as, as, describedAs, describedAs
-
Method Details
-
node
Moves comparison to given node. Second call navigates from the last position in the JSON. -
and
Allows to do multiple comparisons on a document likeassertThatJson("{\"test\":{\"a\":1, \"b\":2, \"c\":3}}").and( a -> a.node("test").isObject(), a -> a.node("test.b").isEqualTo(3) ); -
isEqualTo
Compares JSONs. Ifexpectedis String it's first parsed as JSON. If it can't be parsed as JSON, it is treated as a String. If you want to disambiguate, specify the type first usingisString(),isNumber()etc. Examples:isEqualTo("{\"a\":1}")is parsed as JSONisEqualTo("1")is parsed as number 1isEqualTo("true")is parsed as booleanisEqualTo("\"1\"")is parsed as String "1"isEqualTo("a")is parsed as String "a"
- Specified by:
isEqualToin interfaceorg.assertj.core.api.Assert<JsonAssert, Object>- Overrides:
isEqualToin classorg.assertj.core.api.AbstractAssert<JsonAssert, Object>
-
isStringEqualTo
Assert that the value is string and checks for equality. A shortcut forisString().isEqualTo(expected) -
isObject
Asserts that given node is present and is of type object.- Returns:
- MapAssert where the object is serialized as Map
-
isNumber
public org.assertj.core.api.BigDecimalAssert isNumber()Asserts that given node is present and is of type number. -
isIntegralNumber
public org.assertj.core.api.BigIntegerAssert isIntegralNumber()Asserts that the value is an integer. 1 is an integer 1.0, 1.1, 1e3, 1e0, 1e-3 is not. -
asNumber
public org.assertj.core.api.BigDecimalAssert asNumber()Asserts that given node is present and is of type number or a string that can be parsed as a number. -
isArray
Asserts that given node is present and is of type array. -
isBoolean
public org.assertj.core.api.BooleanAssert isBoolean()Asserts that given node is present and is of type boolean. -
isString
public org.assertj.core.api.StringAssert isString()Asserts that given node is present and is of type string. -
asString
public org.assertj.core.api.AbstractStringAssert<?> asString()- Specified by:
asStringin interfaceorg.assertj.core.api.Assert<JsonAssert, Object>- Overrides:
asStringin classorg.assertj.core.api.AbstractAssert<JsonAssert, Object>
-
isNull
public void isNull()Asserts that given node is present and is null.- Specified by:
isNullin interfaceorg.assertj.core.api.Assert<JsonAssert, Object>- Overrides:
isNullin classorg.assertj.core.api.AbstractAssert<JsonAssert, Object>
-
isUri
public org.assertj.core.api.UriAssert isUri()Asserts that given node is present and is URI. -
isPresent
Asserts that given node is present. -
isAbsent
public void isAbsent()Asserts that given node is absent. -
isNotNull
Asserts that given node is present and is not null.- Specified by:
isNotNullin interfaceorg.assertj.core.api.Assert<JsonAssert, Object>- Overrides:
isNotNullin classorg.assertj.core.api.AbstractAssert<JsonAssert, Object>
-
asInstanceOf
public <ASSERT extends org.assertj.core.api.AbstractAssert<?,?>> ASSERT asInstanceOf(org.assertj.core.api.InstanceOfAssertFactory<?, ASSERT> instanceOfAssertFactory) - Specified by:
asInstanceOfin interfaceorg.assertj.core.api.Assert<JsonAssert, Object>- Overrides:
asInstanceOfin classorg.assertj.core.api.AbstractAssert<JsonAssert, Object>
-