assertEquals("0011 39 02 3661 8300",
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.AU));
}
public void testFormatOutOfCountryKeepingAlphaChars() {
PhoneNumber alphaNumericNumber = new PhoneNumber();
alphaNumericNumber.setCountryCode(1).setNationalNumber(8007493524L)
.setRawInput("1800 six-flag");
assertEquals("0011 1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
alphaNumericNumber.setRawInput("1-800-SIX-flag");
assertEquals("0011 1 800-SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
alphaNumericNumber.setRawInput("Call us from UK: 00 1 800 SIX-flag");
assertEquals("0011 1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
alphaNumericNumber.setRawInput("800 SIX-flag");
assertEquals("0011 1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
// Formatting from within the NANPA region.
assertEquals("1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.US));
assertEquals("1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.BS));
// Testing that if the raw input doesn't exist, it is formatted using
// formatOutOfCountryCallingNumber.
alphaNumericNumber.clearRawInput();
assertEquals("00 1 800 749 3524",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.DE));
// Testing AU alpha number formatted from Australia.
alphaNumericNumber.setCountryCode(61).setNationalNumber(827493524L)
.setRawInput("+61 82749-FLAG");
// This number should have the national prefix fixed.
assertEquals("082749-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
alphaNumericNumber.setRawInput("082749-FLAG");
assertEquals("082749-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
alphaNumericNumber.setNationalNumber(18007493524L).setRawInput("1-800-SIX-flag");
// This number should not have the national prefix prefixed, in accordance with the override for
// this specific formatting rule.
assertEquals("1-800-SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU));
// The metadata should not be permanently changed, since we copied it before modifying patterns.
// Here we check this.
alphaNumericNumber.setNationalNumber(1800749352L);
assertEquals("1800 749 352",
phoneUtil.formatOutOfCountryCallingNumber(alphaNumericNumber, RegionCode.AU));
// Testing a region with multiple international prefixes.
assertEquals("+61 1-800-SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.SG));
// Testing the case of calling from a non-supported region.
assertEquals("+61 1-800-SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ));
// Testing the case with an invalid country calling code.
alphaNumericNumber.setCountryCode(0).setNationalNumber(18007493524L)
.setRawInput("1-800-SIX-flag");
// Uses the raw input only.
assertEquals("1-800-SIX-flag",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.DE));
// Testing the case of an invalid alpha number.
alphaNumericNumber.setCountryCode(1).setNationalNumber(80749L).setRawInput("180-SIX");
// No country-code stripping can be done.
assertEquals("00 1 180-SIX",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.DE));
// Testing the case of calling from a non-supported region.
alphaNumericNumber.setCountryCode(1).setNationalNumber(80749L).setRawInput("180-SIX");
// No country-code stripping can be done since the number is invalid.
assertEquals("+1 180-SIX",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ));
}