2 * Copyright (C) 2011 The Libphonenumber Authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.i18n.phonenumbers;
19 import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
21 import junit.framework.TestCase;
24 * Tests for {@link PhoneNumberMatch}.
26 public class PhoneNumberMatchTest extends TestCase {
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}.
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);
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());
47 * Tests the value type semantics for matches with a null number.
49 public void testIllegalArguments() throws Exception {
51 new PhoneNumberMatch(-110, "1 800 234 45 67", new PhoneNumber());
53 } catch (IllegalArgumentException e) { /* success */ }
56 new PhoneNumberMatch(10, "1 800 234 45 67", null);
58 } catch (NullPointerException e) { /* success */ }
61 new PhoneNumberMatch(10, null, new PhoneNumber());
63 } catch (NullPointerException e) { /* success */ }
66 new PhoneNumberMatch(10, null, null);
68 } catch (NullPointerException e) { /* success */ }