Skip to content

Commit

Permalink
test(node): Make creating a JSON object more readable
Browse files Browse the repository at this point in the history
Use a JSON string instead of programatical construction of the
JSON object.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Apr 12, 2024
1 parent 42821bb commit a9bcec8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions model/src/main/kotlin/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ val EMPTY_JSON_NODE: JsonNode = MissingNode.getInstance()
inline fun <reified T> String.fromYaml(): T = yamlMapper.readValue(this)

fun Any?.toYaml(): String = yamlMapper.writeValueAsString(this)

fun String.readJsonTree(): JsonNode = jsonMapper.readTree(this)
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.readJsonTree

class NpmSupportTest : WordSpec({
"expandNpmShortcutUrl()" should {
Expand Down Expand Up @@ -192,17 +193,16 @@ class NpmSupportTest : WordSpec({

"parseNpmVcsInfo()" should {
"get VCS information from an object node" {
@Suppress("Wrapping")
val node = ObjectMapper().run {
createObjectNode().apply {
replace("gitHead", TextNode("bar"))
replace("repository", createObjectNode().apply {
replace("type", TextNode("Git"))
replace("url", TextNode("https://example.com/"))
replace("directory", TextNode("foo"))
})
val node = """
{
"gitHead": "bar",
"repository": {
"type": "Git",
"url": "https://example.com/",
"directory": "foo"
}
}
""".readJsonTree()

parseNpmVcsInfo(node) shouldBe VcsInfo(
VcsType.GIT,
Expand Down

0 comments on commit a9bcec8

Please sign in to comment.