diff --git a/android/build.gradle.kts b/android/build.gradle.kts index e12fb656..30f87292 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -74,7 +74,13 @@ dependencies { kapt(libs.dagger.compiler) - testImplementation(libs.kotest.assertions.core) - testImplementation(libs.kotest.runner.junit5) + testImplementation(libs.junit.jupiter.api) + testImplementation(libs.truth) { exclude(group = "junit", module = "junit") } + testRuntimeOnly(libs.junit.jupiter.engine) + testRuntimeOnly(libs.junit.legacy) { + // See https://github.com/google/truth/issues/333 + because("Truth needs it") + } + testImplementation(libs.kotlinx.coroutines.test) testImplementation(libs.okhttp.mockwebserver) } diff --git a/android/src/test/kotlin/dev/msfjarvis/claw/android/viewmodel/CSRFRepositoryTest.kt b/android/src/test/kotlin/dev/msfjarvis/claw/android/viewmodel/CSRFRepositoryTest.kt index ca9428ff..5c119658 100644 --- a/android/src/test/kotlin/dev/msfjarvis/claw/android/viewmodel/CSRFRepositoryTest.kt +++ b/android/src/test/kotlin/dev/msfjarvis/claw/android/viewmodel/CSRFRepositoryTest.kt @@ -6,51 +6,58 @@ */ package dev.msfjarvis.claw.android.viewmodel -import io.kotest.core.spec.Spec -import io.kotest.core.spec.style.FunSpec -import io.kotest.matchers.shouldBe +import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest import okhttp3.OkHttpClient import okhttp3.mockwebserver.Dispatcher import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.RecordedRequest +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test -class CSRFRepositoryTest : FunSpec() { - private val server = MockWebServer() - - init { - test("Correctly extracts CSRF token").config(coroutineTestScope = true) { - val repo = - CSRFRepository( - OkHttpClient.Builder().build(), - Dispatchers.Default, - server.url("/").toString(), - ) - repo.extractToken() shouldBe +@OptIn(ExperimentalCoroutinesApi::class) +class CSRFRepositoryTest { + @Test + fun `correctly extracts CSRF token`() = runTest { + val repo = + CSRFRepository( + OkHttpClient.Builder().build(), + Dispatchers.Default, + server.url("/").toString(), + ) + assertThat(repo.extractToken()) + .isEqualTo( "OZWykgFemPVeOSNmB53-ccKXe458X7xCInO1-qzFU6nk_9RCSrSQqS9OPmA5_pyy8qD3IYAIZ7XfAM3gdhJpkQ" - } + ) } - override suspend fun beforeSpec(spec: Spec) { - super.beforeSpec(spec) - val dispatcher = - object : Dispatcher() { - override fun dispatch(request: RecordedRequest): MockResponse { - return when (val path = request.path) { - "/" -> - MockResponse() - .setResponseCode(200) - .setBody( - javaClass.classLoader!! - .getResourceAsStream("csrf_page.html") - .readAllBytes() - .decodeToString(), - ) - else -> error("Invalid path: $path") + companion object { + private val server = MockWebServer() + + @JvmStatic + @BeforeAll + fun setup() { + val dispatcher = + object : Dispatcher() { + override fun dispatch(request: RecordedRequest): MockResponse { + return when (val path = request.path) { + "/" -> + MockResponse() + .setResponseCode(200) + .setBody( + javaClass.classLoader!! + .getResourceAsStream("csrf_page.html") + .readAllBytes() + .decodeToString(), + ) + else -> error("Invalid path: $path") + } } } - } - server.dispatcher = dispatcher + server.dispatcher = dispatcher + } } }