Skip to content

Commit

Permalink
Improve mutable model
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Nov 13, 2023
1 parent 3c5bdf3 commit 6739f11
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,52 +189,54 @@ internal class HttpRequestTest {
}

@Test fun `HTTP Request operators work ok`() {
httpRequestData().let {
val o = it.copy()
val header = Header("h", "v")
it + header

assertEquals(it, o.copy(headers = it.headers + header))
val header = Header("h", "v")
httpRequestCopy().let { (o, r) ->
r + header
assertEquals(r, o.copy(headers = o.headers + header))
}
httpRequestCopy().let { (o, r) ->
r + Headers(header)
assertEquals(r, o.copy(headers = o.headers + header))
}

val queryParameter = QueryParameter("h", "v")
httpRequestCopy().let { (o, r) ->
r + queryParameter
assertEquals(r, o.copy(queryParameters = o.queryParameters + queryParameter))
}
httpRequestCopy().let { (o, r) ->
r + QueryParameters(queryParameter)
assertEquals(r, o.copy(queryParameters = o.queryParameters + queryParameter))
}

val httpPart = HttpPart("h", "v")
httpRequestCopy().let { (o, r) ->
r + httpPart
assertEquals(r, o.copy(parts = o.parts + httpPart))
}
httpRequestCopy().let { (o, r) ->
r + listOf(httpPart)
assertEquals(r, o.copy(parts = o.parts + httpPart))
}

val formParameter = FormParameter("h", "v")
httpRequestCopy().let { (o, r) ->
r + formParameter
assertEquals(r, o.copy(formParameters = o.formParameters + formParameter))
}
httpRequestCopy().let { (o, r) ->
r + FormParameters(formParameter)
assertEquals(r, o.copy(formParameters = o.formParameters + formParameter))
}

val cookie = Cookie("n", "v")
httpRequestCopy().let { (o, r) ->
r + cookie
assertEquals(r, o.copy(cookies = o.cookies + cookie))
}
// assertEquals(
// httpRequest + Headers(header),
// httpRequest.copy(headers = httpRequest.headers + header)
// )
//
// val queryParameter = QueryParameter("h", "v")
// assertEquals(
// httpRequest + queryParameter,
// httpRequest.copy(queryParameters = httpRequest.queryParameters + queryParameter)
// )
// assertEquals(
// httpRequest + QueryParameters(queryParameter),
// httpRequest.copy(queryParameters = httpRequest.queryParameters + queryParameter)
// )
//
// val httpPart = HttpPart("h", "v")
// assertEquals(
// httpRequest + httpPart,
// httpRequest.copy(parts = httpRequest.parts + httpPart)
// )
// assertEquals(
// httpRequest + listOf(httpPart),
// httpRequest.copy(parts = httpRequest.parts + httpPart)
// )
//
// val formParameter = FormParameter("h", "v")
// assertEquals(
// httpRequest + formParameter,
// httpRequest.copy(formParameters = httpRequest.formParameters + formParameter)
// )
// assertEquals(
// httpRequest + FormParameters(formParameter),
// httpRequest.copy(formParameters = httpRequest.formParameters + formParameter)
// )
//
// val cookie = Cookie("n", "v")
// assertEquals(
// httpRequest + cookie,
// httpRequest.copy(cookies = httpRequest.cookies + cookie)
// )
}

private fun httpRequestCopy(): Pair<HttpRequest, HttpRequest> =
httpRequestData().let { it.copy() to it }
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.hexagonkt.http.mutable.model

import com.hexagonkt.core.media.TEXT_HTML
import com.hexagonkt.core.media.TEXT_RICHTEXT
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals

internal class HttpResponseTest {

Expand Down Expand Up @@ -33,26 +31,28 @@ internal class HttpResponseTest {
}

@Test fun `HTTP Response operators work ok`() {
val httpResponse = httpResponseData()

// val header = Header("h", "v")
// assertEquals(
// httpResponse + header,
// httpResponse.copy(headers = httpResponse.headers + header)
// )
// assertEquals(
// httpResponse + Headers(header),
// httpResponse.copy(headers = httpResponse.headers + header)
// )
//
// val cookie = Cookie("n", "v")
// assertEquals(
// httpResponse + cookie,
// httpResponse.copy(cookies = httpResponse.cookies + cookie)
// )
// assertEquals(
// httpResponse + listOf(cookie),
// httpResponse.copy(cookies = httpResponse.cookies + cookie)
// )
val header = Header("h", "v")
httpResponseCopy().let { (o, r) ->
r + header
assertEquals(r, o.copy(headers = o.headers + header))
}
httpResponseCopy().let { (o, r) ->
r + Headers(header)
assertEquals(r, o.copy(headers = o.headers + header))
}

val cookie = Cookie("n", "v")
httpResponseCopy().let { (o, r) ->
r + cookie
assertEquals(r, o.copy(cookies = o.cookies + cookie))
}
httpResponseCopy().let { (o, r) ->
r + listOf(cookie)
assertEquals(r, o.copy(cookies = o.cookies + cookie))
}
}

private fun httpResponseCopy(): Pair<HttpResponse, HttpResponse> =
httpResponseData().let { it.copy() to it }
}

0 comments on commit 6739f11

Please sign in to comment.