Browse Source

JAVA: Fix NullPointerException in PhoneNumberOfflineGeocoder.

pull/567/head
Philippe Liard 14 years ago
committed by Mihaela Rosca
parent
commit
99a60e37be
2 changed files with 13 additions and 1 deletions
  1. +4
    -1
      java/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java
  2. +9
    -0
      java/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java

+ 4
- 1
java/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java View File

@ -179,6 +179,9 @@ public class PhoneNumberOfflineGeocoder {
countryCallingCode : (1000 + (int) (number.getNationalNumber() / 10000000));
AreaCodeMap phonePrefixDescriptions =
getPhonePrefixDescriptions(phonePrefix, lang, script, region);
return (phonePrefixDescriptions != null) ? phonePrefixDescriptions.lookup(number) : "";
String description = phonePrefixDescriptions != null
? phonePrefixDescriptions.lookup(number)
: "";
return description == null ? "" : description;
}
}

+ 9
- 0
java/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java View File

@ -47,6 +47,8 @@ public class PhoneNumberOfflineGeocoderTest extends TestCase {
new PhoneNumber().setCountryCode(1).setNationalNumber(6509600000L);
private static final PhoneNumber US_NUMBER3 =
new PhoneNumber().setCountryCode(1).setNationalNumber(2128120000L);
private static final PhoneNumber US_NUMBER4 =
new PhoneNumber().setCountryCode(1).setNationalNumber(6174240000L);
private static final PhoneNumber US_INVALID_NUMBER =
new PhoneNumber().setCountryCode(1).setNationalNumber(123456789L);
private static final PhoneNumber BS_NUMBER1 =
@ -71,6 +73,13 @@ public class PhoneNumberOfflineGeocoderTest extends TestCase {
new Locale("en", "US")));
}
public void testGetDescriptionForNumberWithMissingPrefix() {
// Test that the name of the country is returned when the number passed in is valid but not
// covered by the geocoding data file.
assertEquals("United States",
geocoder.getDescriptionForNumber(US_NUMBER4, new Locale("en", "US")));
}
public void testGetDescriptionForNumber_en_US() {
assertEquals("CA",
geocoder.getDescriptionForNumber(US_NUMBER1, new Locale("en", "US")));


Loading…
Cancel
Save