@Test
public void testValidateTypeUrl() throws Exception {

  String goodUrlPrefix = "type.googleapis.com/";
  // Some invalid type URLs.
  try {
    Validators.validateTypeUrl("some.bad.url/that.is.invalid");
    fail("Invalid type URL, should have thrown exception");
  } catch (GeneralSecurityException e) {
    // Expected.
    TestUtil.assertExceptionContains(e, "type URL");
    TestUtil.assertExceptionContains(e, "invalid");
  }
  try {
    Validators.validateTypeUrl(goodUrlPrefix);
    fail("Invalid type URL, should have thrown exception.");
  } catch (GeneralSecurityException e) {
    // Expected.
    TestUtil.assertExceptionContains(e, "type URL");
    TestUtil.assertExceptionContains(e, "invalid");
    TestUtil.assertExceptionContains(e, "has no message name");
  }
  // A valid type URL.
  Validators.validateTypeUrl(goodUrlPrefix + "somepackage.somemessage");
}