diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a124ce22..3d1b51e7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,6 +9,7 @@ kotlinpoet = "1.14.2" mavenplugin = "0.25.3" moshi = "1.15.0" okhttp = "4.12.0" +okhttp-junit = "5.0.0-alpha.11" okio = "3.6.0" protobuf = "3.25.0" slf4j = "2.0.9" @@ -46,6 +47,7 @@ moshiKotlinCodegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", versi okhttp-core = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } okhttp-tls = { module = "com.squareup.okhttp3:okhttp-tls", version.ref = "okhttp" } okhttp-mockwebserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okhttp" } +okhttp-mockwebserver-junit4 = { module = "com.squareup.okhttp3:mockwebserver3-junit4", version.ref = "okhttp-junit" } okio-core = { module = "com.squareup.okio:okio", version.ref = "okio" } protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" } protobuf-java-util = { module = "com.google.protobuf:protobuf-java-util", version.ref = "protobuf" } diff --git a/okhttp/build.gradle.kts b/okhttp/build.gradle.kts index e39dcd76..37df48de 100644 --- a/okhttp/build.gradle.kts +++ b/okhttp/build.gradle.kts @@ -19,6 +19,7 @@ dependencies { testImplementation(libs.assertj) testImplementation(libs.okhttp.mockwebserver) + testImplementation(libs.okhttp.mockwebserver.junit4) testImplementation(libs.kotlin.coroutines.test) testImplementation(project(":extensions:google-java")) testImplementation(project(":examples:generated-google-java")) diff --git a/okhttp/src/test/kotlin/com/connectrpc/okhttp/MockWebServerTests.kt b/okhttp/src/test/kotlin/com/connectrpc/okhttp/MockWebServerTests.kt index 4c895935..8730cddb 100644 --- a/okhttp/src/test/kotlin/com/connectrpc/okhttp/MockWebServerTests.kt +++ b/okhttp/src/test/kotlin/com/connectrpc/okhttp/MockWebServerTests.kt @@ -24,21 +24,21 @@ import com.connectrpc.extensions.GoogleJavaProtobufStrategy import com.connectrpc.impl.ProtocolClient import com.connectrpc.protocols.NetworkProtocol import kotlinx.coroutines.test.runTest +import mockwebserver3.MockResponse +import mockwebserver3.junit4.MockWebServerRule import okhttp3.OkHttpClient import okhttp3.Protocol -import okhttp3.mockwebserver.MockResponse -import okhttp3.mockwebserver.MockWebServer import org.assertj.core.api.Assertions.assertThat +import org.junit.Rule import org.junit.Test class MockWebServerTests { + @get:Rule val mockWebServerRule = MockWebServerRule() + @Test fun `compressed empty failure response is parsed correctly`() = runTest { - val mockWebServer = MockWebServer() - mockWebServer.start() - - mockWebServer.enqueue( + mockWebServerRule.server.enqueue( MockResponse().apply { addHeader("accept-encoding", "gzip") addHeader("content-encoding", "gzip") @@ -47,7 +47,7 @@ class MockWebServerTests { }, ) - val host = mockWebServer.url("/") + val host = mockWebServerRule.server.url("/") val protocolClient = ProtocolClient( ConnectOkHttpClient( @@ -66,12 +66,10 @@ class MockWebServerTests { val response = ElizaServiceClient(protocolClient).say(sayRequest { sentence = "hello" }) - mockWebServer.takeRequest().apply { + mockWebServerRule.server.takeRequest().apply { assertThat(path).isEqualTo("/connectrpc.eliza.v1.ElizaService/Say") } assertThat(response.code).isEqualTo(Code.UNKNOWN) - - mockWebServer.shutdown() } } \ No newline at end of file