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.google.i18n.phonenumbers;
     18 
     19 import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
     20 
     21 import junit.framework.TestCase;
     22 
     23 /**
     24  * Tests for {@link PhoneNumberMatch}.
     25  */
     26 public class PhoneNumberMatchTest extends TestCase {
     27   /**
     28    * Tests the value type semantics. Equality and hash code must be based on the covered range and
     29    * corresponding phone number. Range and number correctness are tested by
     30    * {@link PhoneNumberMatcherTest}.
     31    */
     32   public void testValueTypeSemantics() throws Exception {
     33     PhoneNumber number = new PhoneNumber();
     34     PhoneNumberMatch match1 = new PhoneNumberMatch(10, "1 800 234 45 67", number);
     35     PhoneNumberMatch match2 = new PhoneNumberMatch(10, "1 800 234 45 67", number);
     36 
     37     assertEquals(match1, match2);
     38     assertEquals(match1.hashCode(), match2.hashCode());
     39     assertEquals(match1.start(), match2.start());
     40     assertEquals(match1.end(), match2.end());
     41     assertEquals(match1.number(), match2.number());
     42     assertEquals(match1.rawString(), match2.rawString());
     43     assertEquals("1 800 234 45 67", match1.rawString());
     44   }
     45 
     46   /**
     47    * Tests the value type semantics for matches with a null number.
     48    */
     49   public void testIllegalArguments() throws Exception {
     50     try {
     51       new PhoneNumberMatch(-110, "1 800 234 45 67", new PhoneNumber());
     52       fail();
     53     } catch (IllegalArgumentException e) { /* success */ }
     54 
     55     try {
     56       new PhoneNumberMatch(10, "1 800 234 45 67", null);
     57       fail();
     58     } catch (NullPointerException e) { /* success */ }
     59 
     60     try {
     61       new PhoneNumberMatch(10, null, new PhoneNumber());
     62       fail();
     63     } catch (NullPointerException e) { /* success */ }
     64 
     65     try {
     66       new PhoneNumberMatch(10, null, null);
     67       fail();
     68     } catch (NullPointerException e) { /* success */ }
     69   }
     70 }
     71