PhoneNumberLibrary { public static String normalizePhoneNumber(String phoneNumber) { if (phoneNumber == null) return phoneNumber; phoneNumber = phoneNumber.replaceAll("[^\\w]", ""); phoneNumber.replaceAll("_", ""); if (phoneNumber.length() == 10) phoneNumber = "1" + phoneNumber; return phoneNumber; }  static String normalizePhoneNumber(String phoneNumber); static String[] segmentPhoneNumber(String number);  }
@Test public void testNormalizePhoneNumber() { assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("12065551234")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("+12065551234")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("2065551234")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("+2065551234")); assertEquals("5551234", PhoneNumberLibrary.normalizePhoneNumber("5551234")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber(" 1 206 555 1234 ")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("206-555-1234")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("206.555.1234")); assertEquals("12065551234", PhoneNumberLibrary.normalizePhoneNumber("206-555 (1234)")); }