File tree Expand file tree Collapse file tree
main/kotlin/com/ecwid/apiclient/v3
test/kotlin/com/ecwid/apiclient/v3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -557,10 +557,10 @@ private fun createAdditionalDataPolymorphicType(): PolymorphicType<FetchedReport
557557 )
558558}
559559
560- private fun isJsonObject (input : String ): Boolean {
560+ internal fun isJsonObject (input : String? ): Boolean {
561561 return try {
562- JsonParser .parseString(input ).isJsonObject
562+ input?. let { JsonParser .parseString(it ).isJsonObject } ? : false
563563 } catch (_: JsonSyntaxException ) {
564- return false
564+ false
565565 }
566566}
Original file line number Diff line number Diff line change 1+ package com.ecwid.apiclient.v3
2+
3+ import org.junit.jupiter.api.Test
4+ import org.junit.jupiter.params.ParameterizedTest
5+ import org.junit.jupiter.params.provider.ValueSource
6+ import kotlin.test.assertFalse
7+ import kotlin.test.assertTrue
8+
9+ class ApiClientHelperUnitTest {
10+
11+ @Test
12+ fun `should return true if input string is valid json` () {
13+ val testString = " {\" foo\" :\" bar\" }"
14+ assertTrue { isJsonObject(testString) }
15+ }
16+
17+ @ParameterizedTest
18+ @ValueSource(strings = [" some sample text" , " \" foo\" :\" bar\" }" , " " ])
19+ fun `should return false if input string is not json` (input : String ) {
20+ assertFalse { isJsonObject(input) }
21+ }
22+
23+ @Test
24+ fun `should return false if input string is null` () {
25+ val testString = null
26+ assertFalse { isJsonObject(testString) }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments