1
0
mirror of https://github.com/square/okhttp.git synced 2025-07-29 17:41:17 +03:00

Switch to a Builder for mockwebserver3.MockResponse (#7578)

* Switch to a Builder for mockwebserver3.MockResponse

* Migrate lots of tests to MockResponse.Builder

* Improve some code style

* Follow naming conventions in MockResponse.Builder

* Apply side-effects for inTunnel=true

* Update the API
This commit is contained in:
Jesse Wilson
2022-12-28 10:13:49 -05:00
committed by GitHub
parent 4468abf499
commit fe15ccda5b
47 changed files with 3735 additions and 3111 deletions

View File

@ -39,7 +39,6 @@ import org.junit.jupiter.api.fail
import java.io.IOException
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
import org.junit.jupiter.api.BeforeEach
@ExtendWith(MockWebServerExtension::class)
@ -61,7 +60,7 @@ class SuspendCallTest {
@Test
fun suspendCall() {
runTest {
server.enqueue(MockResponse().setBody("abc"))
server.enqueue(MockResponse(body = "abc"))
val call = client.newCall(request)
@ -77,9 +76,10 @@ class SuspendCallTest {
fun timeoutCall() {
runTest {
server.enqueue(
MockResponse()
.setBodyDelay(5, TimeUnit.SECONDS)
.setBody("abc")
MockResponse.Builder()
.bodyDelay(5, TimeUnit.SECONDS)
.body("abc")
.build()
)
val call = client.newCall(request)
@ -105,9 +105,10 @@ class SuspendCallTest {
fun cancelledCall() {
runTest {
server.enqueue(
MockResponse()
.setBodyDelay(5, TimeUnit.SECONDS)
.setBody("abc")
MockResponse.Builder()
.bodyDelay(5, TimeUnit.SECONDS)
.body("abc")
.build()
)
val call = client.newCall(request)
@ -132,9 +133,10 @@ class SuspendCallTest {
fun failedCall() {
runTest {
server.enqueue(
MockResponse()
.setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST)
.setBody("abc")
MockResponse(
body = "abc",
socketPolicy = SocketPolicy.DISCONNECT_AFTER_REQUEST,
)
)
val call = client.newCall(request)