예제 #1
0
 [TestMethod] public void testGetExampleShortNumber()
 {
     assertEquals("8711", shortInfo.getExampleShortNumber(RegionCode.AM));
     assertEquals("1010", shortInfo.getExampleShortNumber(RegionCode.FR));
     assertEquals("", shortInfo.getExampleShortNumber(RegionCode.UN001));
     assertEquals("", shortInfo.getExampleShortNumber(null));
 }
        [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());
        }