Repository: square/okhttp
File: okhttp/src/test/java/okhttp3/HttpUrlTest.java (Java)

Code before:
        .newBuilder()
        .encodedFragment(null)
        .build();
    assertThat(url.toString()).isEqualTo("http://host/");
    assertThat(url.fragment()).isNull();
    assertThat(url.encodedFragment()).isNull();
  }

  @Test public void topPrivateDomain() {
    assertThat(parse("https://google.com").topPrivateDomain()).isEqualTo("google.com");
    assertThat(parse("https://adwords.google.co.uk").topPrivateDomain())
        .isEqualTo("google.co.uk");
    assertThat(parse("https://栃.栃木.jp").topPrivateDomain())
        .isEqualTo("xn--ewv.xn--4pvxs.jp");
    assertThat(parse("https://xn--ewv.xn--4pvxs.jp").topPrivateDomain())
        .isEqualTo("xn--ewv.xn--4pvxs.jp");

    assertThat(parse("https://co.uk").topPrivateDomain()).isNull();
    assertThat(parse("https://square").topPrivateDomain()).isNull();
    assertThat(parse("https://栃木.jp").topPrivateDomain()).isNull();
    assertThat(parse("https://xn--4pvxs.jp").topPrivateDomain()).isNull();
    assertThat(parse("https://localhost").topPrivateDomain()).isNull();
    assertThat(parse("https://127.0.0.1").topPrivateDomain()).isNull();

    // https://github.com/square/okhttp/issues/6109
    assertThat(parse("http://a./").topPrivateDomain()).isNull();
  }

  private void assertInvalid(String string, String exceptionMessage) {
    if (useGet) {
      try {
        parse(string);
        fail("Expected get of \"" + string + "\" to throw with: " + exceptionMessage);
      } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).isEqualTo(exceptionMessage);
      }
    } else {
      assertThat(parse(string)).overridingErrorMessage(string).isNull();
    }
  }
}


Review comment (suggestion):
Also test these?
```
a..
..a
a..b
.a
.
..

```

Code after:
        .newBuilder()
        .encodedFragment(null)
        .build();
    assertThat(url.toString()).isEqualTo("http://host/");
    assertThat(url.fragment()).isNull();
    assertThat(url.encodedFragment()).isNull();
  }

  @Test public void topPrivateDomain() {
    assertThat(parse("https://google.com").topPrivateDomain()).isEqualTo("google.com");
    assertThat(parse("https://adwords.google.co.uk").topPrivateDomain())
        .isEqualTo("google.co.uk");
    assertThat(parse("https://栃.栃木.jp").topPrivateDomain())
        .isEqualTo("xn--ewv.xn--4pvxs.jp");
    assertThat(parse("https://xn--ewv.xn--4pvxs.jp").topPrivateDomain())
        .isEqualTo("xn--ewv.xn--4pvxs.jp");

    assertThat(parse("https://co.uk").topPrivateDomain()).isNull();
    assertThat(parse("https://square").topPrivateDomain()).isNull();
    assertThat(parse("https://栃木.jp").topPrivateDomain()).isNull();
    assertThat(parse("https://xn--4pvxs.jp").topPrivateDomain()).isNull();
    assertThat(parse("https://localhost").topPrivateDomain()).isNull();
    assertThat(parse("https://127.0.0.1").topPrivateDomain()).isNull();

    // https://github.com/square/okhttp/issues/6109
    assertThat(parse("http://a./").topPrivateDomain()).isNull();
    assertThat(parse("http://./").topPrivateDomain()).isNull();

    assertThat(parse("http://squareup.com./").topPrivateDomain()).isEqualTo("squareup.com");
  }

  @Test
  public void unparseableTopPrivateDomain() {
    assertInvalid("http://a../", "Invalid URL host: \"a..\"");
    assertInvalid("http://..a/", "Invalid URL host: \"..a\"");
    assertInvalid("http://a..b/", "Invalid URL host: \"a..b\"");
    assertInvalid("http://.a/", "Invalid URL host: \".a\"");
    assertInvalid("http://../", "Invalid URL host: \"..\"");
  }

  private void assertInvalid(String string, String exceptionMessage) {
    if (useGet) {
      try {
        parse(string);
        fail("Expected get of \"" + string + "\" to throw with: " + exceptionMessage);
      } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).isEqualTo(exceptionMessage);
      }
    } else {
      assertThat(parse(string)).overridingErrorMessage(string).isNull();
    }