Hey everyone, I’m getting the following error whil...
# ktor
g
Hey everyone, I’m getting the following error while trying to test my repository logic
Cannot access '<http://java.io|java.io>.Closeable' which is a supertype of 'io.ktor.client.HttpClient'. Check your module classpath for missing or conflicting dependencies kotlin multiplatform
Can someone help?
Dependencies:
Copy code
sourceSets {
        commonMain.dependencies {
            implementation kotlin("stdlib-common")
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:${versions.coroutines}"
            implementation "io.ktor:ktor-client-core:${versions.ktor}"
            implementation "io.ktor:ktor-client-logging:${versions.ktor}"
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${versions.serialization}"
        }

        commonTest.dependencies {
            implementation kotlin("test-common")
            implementation kotlin("test-annotations-common")
            api "io.ktor:ktor-client-mock:${versions.ktor}"
            implementation "io.mockk:mockk-common:1.10.0"
        }

        androidMain.dependencies {
            implementation kotlin("stdlib-jdk8")
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}"
            implementation "io.ktor:ktor-client-android:${versions.ktor}"
            implementation "io.ktor:ktor-client-logging-jvm:${versions.ktor}"
            implementation "io.ktor:ktor-client-okhttp:${versions.ktor}"
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${versions.serialization}"
        }

        androidTest.dependencies {
            implementation kotlin("test")
            implementation kotlin("test-junit")
            implementation "io.mockk:mockk:1.10.0"
            api "io.ktor:ktor-client-mock-jvm:${versions.ktor}"
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:${versions.coroutines}"
        }

        iosMain.dependencies {
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:${versions.coroutines}"
            implementation "io.ktor:ktor-client-ios:${versions.ktor}"
            implementation "io.ktor:ktor-client-logging-native:${versions.ktor}"
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:${versions.serialization}"
        }

        iosTest {
        }

        jsMain.dependencies {
            implementation kotlin("stdlib-js")
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${versions.coroutines}"
            implementation "io.ktor:ktor-client-js:${versions.ktor}"
            implementation "io.ktor:ktor-client-logging-js:${versions.ktor}"
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${versions.serialization}"
        }

        jsTest.dependencies {
            implementation kotlin("test-js")
            api "io.ktor:ktor-client-mock-js:${versions.ktor}"
        }

        all {
            languageSettings.enableLanguageFeature("InlineClasses")
        }
    }
Failing test:
Copy code
@Test
    fun `fetching random podcast succeeds`() {
        val client = HttpClient(MockEngine) {
            engine {
                addHandler { request ->
                    when (request.url.fullPath) {
                        "/api/v2/just_listen" ->
                            respondOk(
                                """
                                    {
                                      "id": "1",
                                      "podcast_id": "1",
                                      "maybe_audio_invalid": false,
                                      "pub_date_ms": 12345,
                                      "audio": "",
                                      "image": "",
                                      "thumbnail": "",
                                      "description": "description",
                                      "title": "episodeTitle",
                                      "explicit_content": true,
                                      "listennotes_url": "",
                                      "audio_length_sec": 120,
                                      "podcast_title": "Title",
                                      "publisher": "Publisher",
                                      "link": ""
                                    }
                                """.trimIndent()
                            )

                        else -> error("Unhandled case.")
                    }
                }
            }
        }
        val repository: RandomPodcastRepository = RandomPodcastRepositoryImpl(client)

        val actualResult = runBlockingTest { repository.fetch() }

        val expectedResult = Podcast(
            "1", "1", false, Milliseconds(12345), Url(""),
            Url(""), Url(""), "description", "episodeTitle",
            true, "", Seconds(120), "Title", "Publisher", Url("")
        )
        assertEquals(expectedResult, actualResult)
    }
All logic/tests are in
commonMain
.
m
are you using an ancient jdk?
g
JDK 1.8 @mp