diff --git a/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java b/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java index 13c72751bc..978949245a 100644 --- a/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java +++ b/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java @@ -106,7 +106,7 @@ public final class ContactUtil { private static @NonNull String getPrettyPhoneNumber(@NonNull String phoneNumber, @NonNull Locale fallbackLocale) { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); try { - PhoneNumber parsed = util.parse(phoneNumber, fallbackLocale.getISO3Country()); + PhoneNumber parsed = util.parse(phoneNumber, fallbackLocale.getCountry()); return util.format(parsed, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL); } catch (NumberParseException e) { return phoneNumber; diff --git a/test/unitTest/java/org/thoughtcrime/securesms/contactshare/ContactUtilTest_getPrettyPhoneNumber.java b/test/unitTest/java/org/thoughtcrime/securesms/contactshare/ContactUtilTest_getPrettyPhoneNumber.java new file mode 100644 index 0000000000..7e59408aa9 --- /dev/null +++ b/test/unitTest/java/org/thoughtcrime/securesms/contactshare/ContactUtilTest_getPrettyPhoneNumber.java @@ -0,0 +1,55 @@ +package org.thoughtcrime.securesms.contactshare; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public final class ContactUtilTest_getPrettyPhoneNumber { + + private final Locale locale; + private final String input; + private final String expected; + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][]{ + + /* Already international */ + { Locale.US, "+15551234567", "+1 555-123-4567" }, + { Locale.US, "+44 7700900000", "+44 7700 900000" }, + + /* US */ + { Locale.US, "555-123-4567", "+1 555-123-4567" }, + + /* GB */ + { new Locale("en" ,"GB"), "07700900000", "+44 7700 900000" }, + + /* Hungary */ + { new Locale("hu" ,"HU"), "0655153211", "+36 55 153 211" }, + + /* Canaries is a region that does not have an ISO3 country code */ + { new Locale("es", "IC"), "+345551224116", "+34 5551224116" }, + + }); + } + + public ContactUtilTest_getPrettyPhoneNumber(Locale locale, String input, String expected) { + this.locale = locale; + this.input = input; + this.expected = expected; + } + + @Test + public void prettyPhoneNumber() { + String phoneNumber = ContactUtil.getPrettyPhoneNumber(new Contact.Phone(input, Contact.Phone.Type.MOBILE, null), locale); + + assertEquals(expected, phoneNumber); + } +} \ No newline at end of file