Validators { public static void validateTypeUrl(String typeUrl) throws GeneralSecurityException { if (!typeUrl.startsWith(TYPE_URL_PREFIX)) { throw new GeneralSecurityException( String.format( "Error: type URL %s is invalid; it must start with %s.\n", typeUrl, TYPE_URL_PREFIX)); } if (typeUrl.length() == TYPE_URL_PREFIX.length()) { throw new GeneralSecurityException( String.format("Error: type URL %s is invalid; it has no message name.\n", typeUrl)); } } private  Validators(); static void validateTypeUrl(String typeUrl); static void validateAesKeySize(int sizeInBytes); static void validateVersion(int candidate, int maxExpected); static void validateSignatureHash(HashType hash); static void validateRsaModulusSize(int modulusSize); static void validateRsaPublicExponent(
      BigInteger publicExponent); static void validateNotExists(File f); static void validateExists(File f); static String validateKmsKeyUriAndRemovePrefix(String expectedPrefix, String kmsKeyUri); static void validateCryptoKeyUri(String kmsKeyUri);  }
@Test public void testValidateTypeUrl() throws Exception { String goodUrlPrefix = "type.googleapis.com/"; try { Validators.validateTypeUrl("some.bad.url/that.is.invalid"); fail("Invalid type URL, should have thrown exception"); } catch (GeneralSecurityException e) { TestUtil.assertExceptionContains(e, "type URL"); TestUtil.assertExceptionContains(e, "invalid"); } try { Validators.validateTypeUrl(goodUrlPrefix); fail("Invalid type URL, should have thrown exception."); } catch (GeneralSecurityException e) { TestUtil.assertExceptionContains(e, "type URL"); TestUtil.assertExceptionContains(e, "invalid"); TestUtil.assertExceptionContains(e, "has no message name"); } Validators.validateTypeUrl(goodUrlPrefix + "somepackage.somemessage"); }