Repository: square/okhttp
File: okhttp/src/jvmTest/java/okhttp3/CookieTest.kt (Kotlin)

Code before:
  }

  @ParameterizedTest(name = "{displayName}({arguments})")
  @ValueSource(strings = ["Lax", "Strict", "UnrecognizedButValid"])
  fun builderSameSite(sameSite: String) {
    val cookie = Cookie.Builder()
      .name("a")
      .value("b")
      .domain("example.com")
      .sameSite(sameSite)
      .build()
    assertThat(cookie.sameSite).isEqualTo(sameSite)
  }

  @Test fun builderSameSiteNoneRequiresSecure() {
    val cookieBuilder = Cookie.Builder()
      .name("a")
      .value("b")
      .domain("example.com")
      .sameSite("None")

    // assertThrows<IllegalArgumentException> {
    //   cookieBuilder.build()
    // }

    val cookie = cookieBuilder.secure().build()
    assertThat(cookie.sameSite).isEqualTo("None")
  }

  @Test fun equalsAndHashCode() {
    val cookieStrings = Arrays.asList(
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly",
      "a= ; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly",
      "a=b;          Domain=example.com; Max-Age=5; Secure; HttpOnly",
      "a=b; Path=/c;                     Max-Age=5; Secure; HttpOnly",
      "a=b; Path=/c; Domain=example.com;            Secure; HttpOnly",
      "a=b; Path=/c; Domain=example.com; Max-Age=5;         HttpOnly",
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure;         ",
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a= ; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a=b;          Domain=example.com; Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a=b; Path=/c;                     Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a=b; Path=/c; Domain=example.com;            Secure; HttpOnly; SameSite=Lax",
      "a=b; Path=/c; Domain=example.com; Max-Age=5;         HttpOnly; SameSite=Lax",
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure;         ; SameSite=Lax",
    )
    for (stringA in cookieStrings) {
      val cookieA = parseCookie(0, url, stringA!!)
      for (stringB in cookieStrings) {
        val cookieB = parseCookie(0, url, stringB!!)
        if (stringA == stringB) {

Review comment (suggestion):
```suggestion
    val cookie = cookieBuilder.build()
```

Code after:
  }

  @ParameterizedTest(name = "{displayName}({arguments})")
  @ValueSource(strings = ["Lax", "Strict", "UnrecognizedButValid"])
  fun builderSameSite(sameSite: String) {
    val cookie = Cookie.Builder()
      .name("a")
      .value("b")
      .domain("example.com")
      .sameSite(sameSite)
      .build()
    assertThat(cookie.sameSite).isEqualTo(sameSite)
  }

    /** Note that we permit building a cookie that doesn’t follow the rules. */
    @Test fun builderSameSiteNoneDoesNotRequireSecure() {
    val cookieBuilder = Cookie.Builder()
      .name("a")
      .value("b")
      .domain("example.com")
      .sameSite("None")

    val cookie = cookieBuilder.build()
    assertThat(cookie.sameSite).isEqualTo("None")
  }

  @Test fun equalsAndHashCode() {
    val cookieStrings = Arrays.asList(
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly",
      "a= ; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly",
      "a=b;          Domain=example.com; Max-Age=5; Secure; HttpOnly",
      "a=b; Path=/c;                     Max-Age=5; Secure; HttpOnly",
      "a=b; Path=/c; Domain=example.com;            Secure; HttpOnly",
      "a=b; Path=/c; Domain=example.com; Max-Age=5;         HttpOnly",
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure;         ",
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a= ; Path=/c; Domain=example.com; Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a=b;          Domain=example.com; Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a=b; Path=/c;                     Max-Age=5; Secure; HttpOnly; SameSite=Lax",
      "a=b; Path=/c; Domain=example.com;            Secure; HttpOnly; SameSite=Lax",
      "a=b; Path=/c; Domain=example.com; Max-Age=5;         HttpOnly; SameSite=Lax",
      "a=b; Path=/c; Domain=example.com; Max-Age=5; Secure;         ; SameSite=Lax",
    )
    for (stringA in cookieStrings) {
      val cookieA = parseCookie(0, url, stringA!!)
      for (stringB in cookieStrings) {
        val cookieB = parseCookie(0, url, stringB!!)
        if (stringA == stringB) {
          assertThat(cookieB.hashCode()).isEqualTo(cookieA.hashCode())
          assertThat(cookieB).isEqualTo(cookieA)
        } else {