[TestMethod] public void testShortNumbersValidAndCorrectCost()
        {
            List <String> invalidStringCases = new ArrayList <String>();

            foreach (String regionCode in shortNumberInfo.getSupportedRegions())
            {
                if (regionCode == RegionCode.PG)
                {
                    // The only short number for Papua New Guinea is 000, which fails the test, since the
                    // national prefix is 0. This needs to be fixed.
                    continue;
                }
                String exampleShortNumber = shortNumberInfo.getExampleShortNumber(regionCode);
                if (!shortNumberInfo.isValidShortNumber(exampleShortNumber, regionCode))
                {
                    String invalidStringCase = "region_code: " + regionCode + ", national_number: " +
                                               exampleShortNumber;
                    invalidStringCases.add(invalidStringCase);
                    LOGGER.log(Level.SEVERE, "Failed validation for string " + invalidStringCase);
                }
                PhoneNumber phoneNumber = phoneNumberUtil.parse(exampleShortNumber, regionCode);
                if (!shortNumberInfo.isValidShortNumber(phoneNumber))
                {
                    invalidCases.add(phoneNumber);
                    LOGGER.log(Level.SEVERE, "Failed validation for " + phoneNumber.toString());
                }

                foreach (ShortNumberInfo.ShortNumberCost cost in System.Enum.GetValues(typeof(ShortNumberInfo.ShortNumberCost)))
                {
                    exampleShortNumber = shortNumberInfo.getExampleShortNumberForCost(regionCode, cost);
                    if (!exampleShortNumber.equals(""))
                    {
                        phoneNumber = phoneNumberUtil.parse(exampleShortNumber, regionCode);
                        if (cost != shortNumberInfo.getExpectedCost(phoneNumber))
                        {
                            wrongTypeCases.add(phoneNumber);
                            LOGGER.log(Level.SEVERE, "Wrong cost for " + phoneNumber.toString());
                        }
                    }
                }
            }
            assertEquals(0, invalidStringCases.size());
            assertEquals(0, invalidCases.size());
            assertEquals(0, wrongTypeCases.size());
        }
예제 #2
0
        [TestMethod] public void testIsValidShortNumber()
        {
            assertTrue(shortInfo.isValidShortNumber(
                           new PhoneNumber().setCountryCode(33).setNationalNumber(1010L)));
            assertTrue(shortInfo.isValidShortNumber("1010", RegionCode.FR));
            assertFalse(shortInfo.isValidShortNumber(
                            new PhoneNumber().setCountryCode(33).setNationalNumber(123456L)));
            assertFalse(shortInfo.isValidShortNumber("123456", RegionCode.FR));

            // Note that GB and GG share the country calling code 44.
            assertTrue(shortInfo.isValidShortNumber(
                           new PhoneNumber().setCountryCode(44).setNationalNumber(18001L)));
        }