@Test public void givenAValidPackageNameWithTwoFields_whenRevertPackageNameToURL_thenReturnsTheRevertedPackageNameAsDomainName() throws Exception { URL revertPackageNameToURL = revertPackageNameToURL(TEST_VALID_PACKAGE_NAME_WITH_TWO_FIELDS); assertThat( revertPackageNameToURL, is(equalTo(new URL(TEST_EXPECTED_URL_STRING_WITH_VALID_PACKAGE_NAME_WITH_TWO_FIELDS)))); }
public static URL revertPackageNameToURL(@NonNull String candidatePackageName) throws MalformedURLException { checkArgument( isAValidPackageName(candidatePackageName), "A valid package name must be provided"); String[] packageNameFields = candidatePackageName.split(DOT_AS_REGULAR_EXPRESSION); StringBuilder urlAsStringBuilder = new StringBuilder(HTTPS_PROTOCOL_AS_STRING + ": .append(packageNameFields[SECOND_LEVEL_DOMAIN_INDEX]) .append(".") .append(packageNameFields[FIRST_LEVEL_DOMAIN_INDEX]); for (int fieldIndex = 2; fieldIndex < packageNameFields.length; fieldIndex++) { urlAsStringBuilder.append("/") .append(packageNameFields[fieldIndex]); } urlAsStringBuilder.append(DEFAULT_CERTIFICATE_FILE_NAME); return new URL(urlAsStringBuilder.toString()); }
PackageNameHelper { public static URL revertPackageNameToURL(@NonNull String candidatePackageName) throws MalformedURLException { checkArgument( isAValidPackageName(candidatePackageName), "A valid package name must be provided"); String[] packageNameFields = candidatePackageName.split(DOT_AS_REGULAR_EXPRESSION); StringBuilder urlAsStringBuilder = new StringBuilder(HTTPS_PROTOCOL_AS_STRING + ": .append(packageNameFields[SECOND_LEVEL_DOMAIN_INDEX]) .append(".") .append(packageNameFields[FIRST_LEVEL_DOMAIN_INDEX]); for (int fieldIndex = 2; fieldIndex < packageNameFields.length; fieldIndex++) { urlAsStringBuilder.append("/") .append(packageNameFields[fieldIndex]); } urlAsStringBuilder.append(DEFAULT_CERTIFICATE_FILE_NAME); return new URL(urlAsStringBuilder.toString()); } }
PackageNameHelper { public static URL revertPackageNameToURL(@NonNull String candidatePackageName) throws MalformedURLException { checkArgument( isAValidPackageName(candidatePackageName), "A valid package name must be provided"); String[] packageNameFields = candidatePackageName.split(DOT_AS_REGULAR_EXPRESSION); StringBuilder urlAsStringBuilder = new StringBuilder(HTTPS_PROTOCOL_AS_STRING + ": .append(packageNameFields[SECOND_LEVEL_DOMAIN_INDEX]) .append(".") .append(packageNameFields[FIRST_LEVEL_DOMAIN_INDEX]); for (int fieldIndex = 2; fieldIndex < packageNameFields.length; fieldIndex++) { urlAsStringBuilder.append("/") .append(packageNameFields[fieldIndex]); } urlAsStringBuilder.append(DEFAULT_CERTIFICATE_FILE_NAME); return new URL(urlAsStringBuilder.toString()); }  }
PackageNameHelper { public static URL revertPackageNameToURL(@NonNull String candidatePackageName) throws MalformedURLException { checkArgument( isAValidPackageName(candidatePackageName), "A valid package name must be provided"); String[] packageNameFields = candidatePackageName.split(DOT_AS_REGULAR_EXPRESSION); StringBuilder urlAsStringBuilder = new StringBuilder(HTTPS_PROTOCOL_AS_STRING + ": .append(packageNameFields[SECOND_LEVEL_DOMAIN_INDEX]) .append(".") .append(packageNameFields[FIRST_LEVEL_DOMAIN_INDEX]); for (int fieldIndex = 2; fieldIndex < packageNameFields.length; fieldIndex++) { urlAsStringBuilder.append("/") .append(packageNameFields[fieldIndex]); } urlAsStringBuilder.append(DEFAULT_CERTIFICATE_FILE_NAME); return new URL(urlAsStringBuilder.toString()); }  static boolean isAValidPackageName(@NonNull String candidatePackageName); static URL revertPackageNameToURL(@NonNull String candidatePackageName); }
PackageNameHelper { public static URL revertPackageNameToURL(@NonNull String candidatePackageName) throws MalformedURLException { checkArgument( isAValidPackageName(candidatePackageName), "A valid package name must be provided"); String[] packageNameFields = candidatePackageName.split(DOT_AS_REGULAR_EXPRESSION); StringBuilder urlAsStringBuilder = new StringBuilder(HTTPS_PROTOCOL_AS_STRING + ": .append(packageNameFields[SECOND_LEVEL_DOMAIN_INDEX]) .append(".") .append(packageNameFields[FIRST_LEVEL_DOMAIN_INDEX]); for (int fieldIndex = 2; fieldIndex < packageNameFields.length; fieldIndex++) { urlAsStringBuilder.append("/") .append(packageNameFields[fieldIndex]); } urlAsStringBuilder.append(DEFAULT_CERTIFICATE_FILE_NAME); return new URL(urlAsStringBuilder.toString()); }  static boolean isAValidPackageName(@NonNull String candidatePackageName); static URL revertPackageNameToURL(@NonNull String candidatePackageName);  }