File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
main/kotlin/com/uzabase/playtest2/http/zoom
test/kotlin/com/uzabase/playtest2/http/zoom Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -108,11 +108,11 @@ internal class IndefiniteJsonPathProxy(
108108 }
109109 }
110110
111- override fun shouldBeExist (): Boolean {
112- TODO (" Not yet implemented" )
113- }
111+ /* **
112+ * Indefinite なパスの場合、存在しないパスでも必ずリストが返ってくるので、例外の考慮は不要…?
113+ ***/
114+ override fun shouldBeExist (): Boolean =
115+ JsonPath .parse(json).read<List <Any >>(path).isNotEmpty()
114116
115- override fun shouldNotBeExist (): Boolean {
116- TODO (" Not yet implemented" )
117- }
117+ override fun shouldNotBeExist (): Boolean = ! shouldBeExist()
118118}
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import io.kotest.assertions.throwables.shouldThrow
55import io.kotest.core.spec.style.FunSpec
66import io.kotest.data.forAll
77import io.kotest.data.row
8+ import io.kotest.matchers.booleans.shouldBeFalse
89import io.kotest.matchers.booleans.shouldBeTrue
9- import io.kotest.matchers.should
1010import io.kotest.matchers.shouldBe
1111
1212class JsonPathProxyTest : FunSpec ({
@@ -142,5 +142,20 @@ class JsonPathProxyTest : FunSpec({
142142 .shouldMatch(".*")
143143 }.message.shouldBe("The path is indefinite and the result is not a single value")
144144 }
145+
146+ test("should be false if empty after filtering - should be exist") {
147+ JsonPathProxy .of(json, "$.people[? (@.name == 'xyz')].name")
148+ .shouldBeExist().shouldBe(false)
149+ }
150+
151+ test("should be true if not empty after filtering - should be exist") {
152+ JsonPathProxy .of(json, "$.people[? (@.name == 'abc')].name")
153+ .shouldBeExist().shouldBe(true)
154+ }
155+
156+ test("should be false if path not found - should be exist") {
157+ JsonPathProxy .of(json, "$.people[? (@.age > 0)][999]")
158+ .shouldBeExist().shouldBeFalse()
159+ }
145160 }
146161})
You can’t perform that action at this time.
0 commit comments