Skip to content

Commit

Permalink
KDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Sep 14, 2023
1 parent d93b1fd commit dcb9d2c
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ fun beJsonNumber(): Matcher<Any?> = beType(NodeType.NUMBER)
fun beJsonBoolean(): Matcher<Any?> = beType(NodeType.BOOLEAN)

/**
* Returns matcher that asserts that given JSON node is null.
* Returns matcher that asserts that given JSON node is present and null.
*/
fun beJsonNull(): Matcher<Any?> = beType(NodeType.NULL)

/**
* Returns matcher that asserts that given JSON node is present.
*/
fun bePresent(): Matcher<Any?> = Matcher { actual ->
val node = getNode(actual)
MatcherResult(
Expand All @@ -101,25 +104,41 @@ private fun beType(expectedType: NodeType): Matcher<Any?> = bePresent() and Matc

private fun getNode(actual: Any?): Node = JsonUtils.getNode(actual, "")

/**
* Asserts that JSON node is present, is a number and returns the value as [BigDecimal].
*/
fun Any?.shouldBeJsonNumber(): BigDecimal {
this should beJsonNumber()
return getNode(this).decimalValue()
}

/**
* Asserts that JSON node is present, is a string and returns the value as [String].
*/
fun Any?.shouldBeJsonString(): String {
this should beJsonString()
return getNode(this).asText()
}

/**
* Asserts that JSON node is present, is a boolean and returns the value as [Boolean].
*/
fun Any?.shouldBeJsonBoolean(): Boolean {
this should beJsonBoolean()
return getNode(this).asBoolean()
}

/**
* Asserts that JSON node is present, is an array and returns the value as [List].
*/
fun Any?.shouldBeJsonArray(): List<*> {
this should beJsonArray()
return getNode(this).value as List<*>
}

/**
* Asserts that JSON node is present, is an object and returns the value as [Map].
*/
fun Any?.shouldBeJsonObject(): Map<String, *> {
this should beJsonObject()
@Suppress("UNCHECKED_CAST")
Expand Down

0 comments on commit dcb9d2c

Please sign in to comment.