### Question:
PhoneNumberUtils { @Nullable static String formatPhoneNumber(@NonNull String phoneNumber, @NonNull CountryInfo countryInfo) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return android.telephony.PhoneNumberUtils .formatNumberToE164(phoneNumber, countryInfo.locale.getCountry()); } return phoneNumber.startsWith("+") ? phoneNumber : ("+" + String.valueOf(countryInfo.countryCode) + phoneNumber.replaceAll("[^\\d.]", "")); }  @Nullable static Integer getCountryCode(String countryIso);  }### Answer:
@Test @Config(constants = BuildConfig.class, sdk = 21) public void testFormatNumberToE164_aboveApi21() { String validPhoneNumber = "+919994947354"; CountryInfo indiaCountryInfo = new CountryInfo(new Locale("", "IN"), 91); assertEquals(validPhoneNumber, formatPhoneNumber("9994947354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("919994947354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("+919994947354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("+91-(999)-(49)-(47354)", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("+91 99949 47354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("91 99949 47354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("(99949) 47-354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("+919994947354", new CountryInfo( new Locale("", "US"), 1))); assertNull(formatPhoneNumber("999474735", indiaCountryInfo)); assertNull(validPhoneNumber, formatPhoneNumber("919994947354", new CountryInfo( new Locale("", "US"), 1))); assertNull(formatPhoneNumber("+914349873457", new CountryInfo( new Locale("", "US"), 1))); }
@Test @Config(constants = BuildConfig.class, sdk = 16) public void testFormatNumberToE164_belowApi21() { String validPhoneNumber = "+919994947354"; CountryInfo indiaCountryInfo = new CountryInfo(new Locale("", "IN"), 91); assertEquals(validPhoneNumber, formatPhoneNumber("9994947354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("+919994947354", indiaCountryInfo)); assertEquals(validPhoneNumber, formatPhoneNumber("(99949) 47-354", indiaCountryInfo)); }