Пример #1
0
        /**
         * Tests the value type semantics. Equality and hash code must be based on the covered range and
         * corresponding phone number. Range and number correctness are tested by
         * {@link PhoneNumberMatcherTest}.
         */
        [TestMethod] public void testValueTypeSemantics()
        {
            PhoneNumber      number = new PhoneNumber();
            PhoneNumberMatch match1 = new PhoneNumberMatch(10, "1 800 234 45 67", number);
            PhoneNumberMatch match2 = new PhoneNumberMatch(10, "1 800 234 45 67", number);

            assertEquals(match1, match2);
            assertEquals(match1.hashCode(), match2.hashCode());
            assertEquals(match1.start(), match2.start());
            assertEquals(match1.end(), match2.end());
            assertEquals(match1.number(), match2.number());
            assertEquals(match1.rawString(), match2.rawString());
            assertEquals("1 800 234 45 67", match1.rawString());
        }
        public boolean equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is PhoneNumberMatch))
            {
                return(false);
            }
            PhoneNumberMatch other = (PhoneNumberMatch)obj;

            return(_rawString.equals(other._rawString) && (_start == other._start) &&
                   _number.equals(other._number));
        }
        public void testSequences()
        {
            // Test multiple occurrences.
            String text = "Call 033316005  or 032316005!";
            String region = RegionCode.NZ;

            PhoneNumber number1 = new PhoneNumber();
            number1.setCountryCode(phoneUtil.getCountryCodeForRegion(region));
            number1.setNationalNumber(33316005);
            PhoneNumberMatch match1 = new PhoneNumberMatch(5, "033316005", number1);

            PhoneNumber number2 = new PhoneNumber();
            number2.setCountryCode(phoneUtil.getCountryCodeForRegion(region));
            number2.setNationalNumber(32316005);
            PhoneNumberMatch match2 = new PhoneNumberMatch(19, "032316005", number2);

            Iterator<PhoneNumberMatch> matches =
            phoneUtil.findNumbers(text, region, Leniency.POSSIBLE, Long.MAX_VALUE).iterator();

            assertEquals(match1, matches.next());
            assertEquals(match2, matches.next());
        }
        public void testValueTypeSemantics()
        {
            PhoneNumber number = new PhoneNumber();
            PhoneNumberMatch match1 = new PhoneNumberMatch(10, "1 800 234 45 67", number);
            PhoneNumberMatch match2 = new PhoneNumberMatch(10, "1 800 234 45 67", number);

            assertEquals(match1, match2);
            assertEquals(match1.hashCode(), match2.hashCode());
            assertEquals(match1.start(), match2.start());
            assertEquals(match1.end(), match2.end());
            assertEquals(match1.number(), match2.number());
            assertEquals(match1.rawString(), match2.rawString());
            assertEquals("1 800 234 45 67", match1.rawString());
        }
        public void testMatchesMultiplePhoneNumbersSeparatedByPhoneNumberPunctuation()
        {
            String text = "Call 650-253-4561 -- 455-234-3451";
            String region = RegionCode.US;

            PhoneNumber number1 = new PhoneNumber();
            number1.setCountryCode(phoneUtil.getCountryCodeForRegion(region));
            number1.setNationalNumber(6502534561L);
            PhoneNumberMatch match1 = new PhoneNumberMatch(5, "650-253-4561", number1);

            PhoneNumber number2 = new PhoneNumber();
            number2.setCountryCode(phoneUtil.getCountryCodeForRegion(region));
            number2.setNationalNumber(4552343451L);
            PhoneNumberMatch match2 = new PhoneNumberMatch(21, "455-234-3451", number2);

            Iterator<PhoneNumberMatch> matches = phoneUtil.findNumbers(text, region).iterator();
            assertEquals(match1, matches.next());
            assertEquals(match2, matches.next());
        }