mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-12 08:48:34 +00:00
parent
14999800e2
commit
840c493265
@ -106,7 +106,7 @@ public final class ContactUtil {
|
|||||||
private static @NonNull String getPrettyPhoneNumber(@NonNull String phoneNumber, @NonNull Locale fallbackLocale) {
|
private static @NonNull String getPrettyPhoneNumber(@NonNull String phoneNumber, @NonNull Locale fallbackLocale) {
|
||||||
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||||
try {
|
try {
|
||||||
PhoneNumber parsed = util.parse(phoneNumber, fallbackLocale.getISO3Country());
|
PhoneNumber parsed = util.parse(phoneNumber, fallbackLocale.getCountry());
|
||||||
return util.format(parsed, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
|
return util.format(parsed, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
|
||||||
} catch (NumberParseException e) {
|
} catch (NumberParseException e) {
|
||||||
return phoneNumber;
|
return phoneNumber;
|
||||||
|
@ -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<Object[]> 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user