diff --git a/shared/src/androidUnitTest/kotlin/com/example/leveldetektor/Test.android.kt b/shared/src/androidUnitTest/kotlin/com/example/kmptemplate/Test.android.kt similarity index 100% rename from shared/src/androidUnitTest/kotlin/com/example/leveldetektor/Test.android.kt rename to shared/src/androidUnitTest/kotlin/com/example/kmptemplate/Test.android.kt diff --git a/shared/src/commonTest/kotlin/com/example/kmptemplate/Test.kt b/shared/src/commonTest/kotlin/com/example/kmptemplate/Test.kt new file mode 100644 index 0000000..28da842 --- /dev/null +++ b/shared/src/commonTest/kotlin/com/example/kmptemplate/Test.kt @@ -0,0 +1,39 @@ +package com.example.kmptemplate + +import Greeting +import io.ktor.client.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.http.* +import io.ktor.serialization.kotlinx.json.* +import io.ktor.utils.io.* +import kotlinx.coroutines.test.runTest +import kotlinx.serialization.json.Json +import kotlin.test.Test +import kotlin.test.assertTrue + +class CommonGreetingTest { + + fun testExample() { + runTest{ + val mockEngine = MockEngine { request -> + respond( + content = ByteReadChannel("""[{"name":"CTS21","flight_number":42,"success":true,"date_utc":"2021-09-15T00:00:00Z"}]"""), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString()) + ) + } + + val mockHttpClient = HttpClient(mockEngine) { + install(ContentNegotiation) { + json(Json { + prettyPrint = true + isLenient = true + ignoreUnknownKeys = true + }) + } + } + assertTrue("Check 2021-09 is mentioned", Greeting(mockHttpClient).greet().contains("Greetings!")) + + } + } +} \ No newline at end of file diff --git a/shared/src/commonTest/kotlin/com/example/leveldetektor/Test.kt b/shared/src/commonTest/kotlin/com/example/leveldetektor/Test.kt deleted file mode 100644 index c938892..0000000 --- a/shared/src/commonTest/kotlin/com/example/leveldetektor/Test.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.kmptemplate - -import Greeting -import kotlin.test.Test -import kotlin.test.assertTrue - -class CommonGreetingTest { - - @Test - fun testExample() { -// assertTrue(Greeting().greet().contains("Hello"), "Check 'Hello' is mentioned") - } -} \ No newline at end of file diff --git a/shared/src/iosTest/kotlin/com/example/kmptemplate/Test.ios.kt b/shared/src/iosTest/kotlin/com/example/kmptemplate/Test.ios.kt new file mode 100644 index 0000000..17f8760 --- /dev/null +++ b/shared/src/iosTest/kotlin/com/example/kmptemplate/Test.ios.kt @@ -0,0 +1,43 @@ +package com.example.kmptemplate + +import Greeting +import io.ktor.client.* +import io.ktor.client.engine.mock.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.http.* +import io.ktor.serialization.kotlinx.json.* +import io.ktor.utils.io.* +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import kotlinx.serialization.json.Json +import kotlin.test.Test +import kotlin.test.assertTrue + +class IosGreetingTest { + + @OptIn(ExperimentalCoroutinesApi::class) + @Test + fun testExample() { + runTest{ + val mockEngine = MockEngine { request -> + respond( + content = ByteReadChannel("""[{"name":"CTS21","flight_number":42,"success":true,"date_utc":"2021-09-15T00:00:00Z"}]"""), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString()) + ) + } + + val mockHttpClient = HttpClient(mockEngine) { + install(ContentNegotiation) { + json(Json { + prettyPrint = true + isLenient = true + ignoreUnknownKeys = true + }) + } + } + assertTrue("Check 2021-09 is mentioned", Greeting(mockHttpClient).greet().contains("Greetings!")) + + } + } +} \ No newline at end of file diff --git a/shared/src/iosTest/kotlin/com/example/leveldetektor/Test.ios.kt b/shared/src/iosTest/kotlin/com/example/leveldetektor/Test.ios.kt deleted file mode 100644 index 62b5375..0000000 --- a/shared/src/iosTest/kotlin/com/example/leveldetektor/Test.ios.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.kmptemplate - -import Greeting -import kotlin.test.Test -import kotlin.test.assertTrue - -class IosGreetingTest { - - @Test - fun testExample() { -// assertTrue(Greeting().greet().contains("iOS"), "Check iOS is mentioned") - } -} \ No newline at end of file