public void validateUniverseDomain() throws IOException {
    if (!(httpRequestInitializer instanceof HttpCredentialsAdapter)) {
      return;
    }
    Credentials credentials = ((HttpCredentialsAdapter) httpRequestInitializer).getCredentials();
    // No need for a null check as HttpCredentialsAdapter cannot be initialized with null
    // Credentials
    String expectedUniverseDomain = credentials.getUniverseDomain();
    if (!expectedUniverseDomain.equals(getUniverseDomain())) {
      throw new IllegalStateException(
          String.format(
              "The configured universe domain (%s) does not match the universe domain found"
                  + " in the credentials (%s). If you haven't configured the universe domain"
                  + " explicitly, `googleapis.com` is the default.",
              getUniverseDomain(), expectedUniverseDomain));
    }
  }
@Test
  public void validateUniverseDomain_notUsingHttpCredentialsAdapter_defaultUniverseDomain()
      throws IOException {
    String rootUrl = "https://test.googleapis.com/";
    String applicationName = "Test Application";
    String servicePath = "test/";

    AbstractGoogleClient client =
        new MockGoogleClient.Builder(
                TRANSPORT,
                rootUrl,
                servicePath,
                JSON_OBJECT_PARSER,
                new TestHttpRequestInitializer())
            .setApplicationName(applicationName)
            .build();

    // Nothing throws
    client.validateUniverseDomain();
  }