Home | History | Annotate | Download | only in phonenumbers
      1 /*
      2  * Copyright (C) 2011 The Libphonenumber Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.i18n.phonenumbers;
     18 
     19 import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
     20 
     21 import junit.framework.TestCase;
     22 
     23 /**
     24  * Tests for {@link PhoneNumberMatch}.
     25  *
     26  * @author Tom Hofmann
     27  */
     28 public class PhoneNumberMatchTest extends TestCase {
     29   /**
     30    * Tests the value type semantics. Equality and hash code must be based on the covered range and
     31    * corresponding phone number. Range and number correctness are tested by
     32    * {@link PhoneNumberMatcherTest}.
     33    */
     34   public void testValueTypeSemantics() throws Exception {
     35     PhoneNumber number = new PhoneNumber();
     36     PhoneNumberMatch match1 = new PhoneNumberMatch(10, "1 800 234 45 67", number);
     37     PhoneNumberMatch match2 = new PhoneNumberMatch(10, "1 800 234 45 67", number);
     38 
     39     assertEquals(match1, match2);
     40     assertEquals(match1.hashCode(), match2.hashCode());
     41     assertEquals(match1.start(), match2.start());
     42     assertEquals(match1.end(), match2.end());
     43     assertEquals(match1.number(), match2.number());
     44     assertEquals(match1.rawString(), match2.rawString());
     45     assertEquals("1 800 234 45 67", match1.rawString());
     46   }
     47 
     48   /**
     49    * Tests the value type semantics for matches with a null number.
     50    */
     51   public void testIllegalArguments() throws Exception {
     52     try {
     53       new PhoneNumberMatch(-110, "1 800 234 45 67", new PhoneNumber());
     54       fail();
     55     } catch (IllegalArgumentException e) { /* success */ }
     56 
     57     try {
     58       new PhoneNumberMatch(10, "1 800 234 45 67", null);
     59       fail();
     60     } catch (NullPointerException e) { /* success */ }
     61 
     62     try {
     63       new PhoneNumberMatch(10, null, new PhoneNumber());
     64       fail();
     65     } catch (NullPointerException e) { /* success */ }
     66 
     67     try {
     68       new PhoneNumberMatch(10, null, null);
     69       fail();
     70     } catch (NullPointerException e) { /* success */ }
     71   }
     72 }
     73