Repository: square/okhttp
File: okhttp/src/test/java/okhttp3/CacheTest.kt (Kotlin)

Code before:

    // The original 'A' header is retained because the network response doesn't have one.
    // The original 'B' headers are replaced by the network response.
    // The network's 'C' header is added.
    val response2 = get(server.url("/"))
    assertThat(response2.body.string()).isEqualTo("abcd")
    assertThat(response2.headers).isEqualTo(
      headersOf(
        "Etag", "a", "Cache-Control", "max-age=0",
        "A", "a1", "Content-Length", "4", "B", "b4", "B", "b5", "C", "c6",
      ),
    )
  }

  @Test
  fun getHasCorrectResponseIsCorrect() {
    val request = Request(server.url("/abc"))

    val response = testBasicCachingRules(request)

    assertThat(response.request.url).isEqualTo(request.url)
    assertThat(response.cacheResponse!!.request.url).isEqualTo(request.url)
  }

  @Test
  fun postWithOverrideResponseIsCorrect() {
    val url = server.url("/abc?token=123")
    val cacheUrlOverride = url.newBuilder().removeAllQueryParameters("token").build()

    val request =
      Request.Builder()
        .url(url)
        .method("POST", "XYZ".toRequestBody())
        .cacheUrlOverride(cacheUrlOverride)
        .build()

    val response = testBasicCachingRules(request)

    assertThat(response.request.url).isEqualTo(request.url)
    assertThat(response.cacheResponse!!.request.url).isEqualTo(cacheUrlOverride)
  }

  private fun testBasicCachingRules(request: Request): Response {
    val mockResponse =
      MockResponse.Builder()
        .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
        .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
        .status("HTTP/1.1 200 Fantastic")
    server.enqueue(mockResponse.build())

    client.newCall(request).execute().use {

Review comment (suggestion):
```suggestion
  fun postWithOverrideResponse() {
```

Code after:

    // The original 'A' header is retained because the network response doesn't have one.
    // The original 'B' headers are replaced by the network response.
    // The network's 'C' header is added.
    val response2 = get(server.url("/"))
    assertThat(response2.body.string()).isEqualTo("abcd")
    assertThat(response2.headers).isEqualTo(
      headersOf(
        "Etag", "a", "Cache-Control", "max-age=0",
        "A", "a1", "Content-Length", "4", "B", "b4", "B", "b5", "C", "c6",
      ),
    )
  }

  @Test
  fun getHasCorrectResponse() {
    val request = Request(server.url("/abc"))

    val response = testBasicCachingRules(request)

    assertThat(response.request.url).isEqualTo(request.url)
    assertThat(response.cacheResponse!!.request.url).isEqualTo(request.url)
  }

  @Test
  fun postWithOverrideResponse() {
    val url = server.url("/abc?token=123")
    val cacheUrlOverride = url.newBuilder().removeAllQueryParameters("token").build()

    val request =
      Request.Builder()
        .url(url)
        .method("POST", "XYZ".toRequestBody())
        .cacheUrlOverride(cacheUrlOverride)
        .build()

    val response = testBasicCachingRules(request)

    assertThat(response.request.url).isEqualTo(request.url)
    assertThat(response.cacheResponse!!.request.url).isEqualTo(cacheUrlOverride)
  }

  private fun testBasicCachingRules(request: Request): Response {
    val mockResponse =
      MockResponse.Builder()
        .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
        .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
        .status("HTTP/1.1 200 Fantastic")
    server.enqueue(mockResponse.build())

    client.newCall(request).execute().use {