@@ -27,9 +27,10 @@ import com.connectrpc.extensions.GoogleJavaProtobufStrategy
2727import com.connectrpc.impl.ProtocolClient
2828import com.connectrpc.protocols.NetworkProtocol
2929import kotlinx.coroutines.test.runTest
30+ import mockwebserver3.MockResponse
31+ import mockwebserver3.junit4.MockWebServerRule
3032import okhttp3.OkHttpClient
3133import okhttp3.Protocol
32- import okhttp3.mockwebserver.MockResponse
3334import org.assertj.core.api.Assertions.assertThat
3435import org.junit.Rule
3536import org.junit.Test
@@ -45,16 +46,16 @@ class MockWebServerTests {
4546 @Test
4647 fun `invalid compressed failure response is handled correctly` () = runTest {
4748 mockWebServerRule.server.enqueue(
48- MockResponse ().apply {
49+ MockResponse . Builder ().apply {
4950 addHeader(" accept-encoding" , " gzip" )
5051 addHeader(" content-encoding" , " gzip" )
51- setBody (" {}" )
52- setResponseCode (401 )
53- },
52+ body (" {}" )
53+ code (401 )
54+ }.build() ,
5455 )
5556 val response = createClient().say(sayRequest { sentence = " hello" })
5657 mockWebServerRule.server.takeRequest().apply {
57- assertThat(path ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
58+ assertThat(target ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
5859 }
5960 assertThat(response).isInstanceOf(ResponseMessage ::class .java)
6061 response.failure { assertThat(it.cause.code).isEqualTo(Code .INTERNAL_ERROR ) }
@@ -63,16 +64,16 @@ class MockWebServerTests {
6364 @Test
6465 fun `invalid compressed response data is handled correctly` () = runTest {
6566 mockWebServerRule.server.enqueue(
66- MockResponse ().apply {
67+ MockResponse . Builder ().apply {
6768 addHeader(" accept-encoding" , " gzip" )
6869 addHeader(" content-encoding" , " gzip" )
69- setBody (" this isn't gzipped" )
70- setResponseCode (200 )
71- },
70+ body (" this isn't gzipped" )
71+ code (200 )
72+ }.build() ,
7273 )
7374 val response = createClient().say(sayRequest { sentence = " hello" })
7475 mockWebServerRule.server.takeRequest().apply {
75- assertThat(path ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
76+ assertThat(target ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
7677 }
7778 assertThat(response).isInstanceOf(ResponseMessage ::class .java)
7879 response.failure { assertThat(it.cause.code).isEqualTo(Code .INTERNAL_ERROR ) }
@@ -81,16 +82,16 @@ class MockWebServerTests {
8182 @Test
8283 fun `invalid protobuf response data is handled correctly` () = runTest {
8384 mockWebServerRule.server.enqueue(
84- MockResponse ().apply {
85+ MockResponse . Builder ().apply {
8586 addHeader(" accept-encoding" , " gzip" )
8687 addHeader(" content-type" , " application/proto" )
87- setBody (" this isn't valid protobuf" )
88- setResponseCode (200 )
89- },
88+ body (" this isn't valid protobuf" )
89+ code (200 )
90+ }.build() ,
9091 )
9192 val response = createClient().say(sayRequest { sentence = " hello" })
9293 mockWebServerRule.server.takeRequest().apply {
93- assertThat(path ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
94+ assertThat(target ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
9495 }
9596 assertThat(response).isInstanceOf(ResponseMessage ::class .java)
9697 response.failure { assertThat(it.cause.code).isEqualTo(Code .INTERNAL_ERROR ) }
@@ -99,16 +100,16 @@ class MockWebServerTests {
99100 @Test
100101 fun `invalid json response data is handled correctly` () = runTest {
101102 mockWebServerRule.server.enqueue(
102- MockResponse ().apply {
103+ MockResponse . Builder ().apply {
103104 addHeader(" accept-encoding" , " gzip" )
104105 addHeader(" content-type" , " application/json" )
105- setBody (" { invalid json" )
106- setResponseCode (200 )
107- },
106+ body (" { invalid json" )
107+ code (200 )
108+ }.build() ,
108109 )
109110 val response = createClient(serializationStrategy = GoogleJavaJSONStrategy ()).say(sayRequest { sentence = " hello" })
110111 mockWebServerRule.server.takeRequest().apply {
111- assertThat(path ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
112+ assertThat(target ).isEqualTo(" /connectrpc.eliza.v1.ElizaService/Say" )
112113 }
113114 assertThat(response).isInstanceOf(ResponseMessage ::class .java)
114115 response.failure { assertThat(it.cause.code).isEqualTo(Code .INTERNAL_ERROR ) }
0 commit comments