1 /* 2 * Copyright (C) 2013 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.prefixmapper; 18 19 import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber; 20 import junit.framework.TestCase; 21 22 /** 23 * Unit tests for PrefixFileReader.java 24 * 25 * @author Cecilia Roes 26 */ 27 public class PrefixFileReaderTest extends TestCase { 28 private final PrefixFileReader reader = new PrefixFileReader(TEST_MAPPING_DATA_DIRECTORY); 29 private static final String TEST_MAPPING_DATA_DIRECTORY = 30 "/com/android/i18n/phonenumbers/geocoding/testing_data/"; 31 32 private static final PhoneNumber KO_NUMBER = 33 new PhoneNumber().setCountryCode(82).setNationalNumber(22123456L); 34 private static final PhoneNumber US_NUMBER1 = 35 new PhoneNumber().setCountryCode(1).setNationalNumber(6502530000L); 36 private static final PhoneNumber US_NUMBER2 = 37 new PhoneNumber().setCountryCode(1).setNationalNumber(2128120000L); 38 private static final PhoneNumber US_NUMBER3 = 39 new PhoneNumber().setCountryCode(1).setNationalNumber(6174240000L); 40 private static final PhoneNumber SE_NUMBER = 41 new PhoneNumber().setCountryCode(46).setNationalNumber(81234567L); 42 testGetDescriptionForNumberWithMapping()43 public void testGetDescriptionForNumberWithMapping() { 44 assertEquals("Kalifornien", 45 reader.getDescriptionForNumber(US_NUMBER1, "de", "", "CH")); 46 assertEquals("CA", 47 reader.getDescriptionForNumber(US_NUMBER1, "en", "", "AU")); 48 assertEquals("\uC11C\uC6B8", 49 reader.getDescriptionForNumber(KO_NUMBER, "ko", "", "")); 50 assertEquals("Seoul", 51 reader.getDescriptionForNumber(KO_NUMBER, "en", "", "")); 52 } 53 testGetDescriptionForNumberWithMissingMapping()54 public void testGetDescriptionForNumberWithMissingMapping() { 55 assertEquals("", reader.getDescriptionForNumber(US_NUMBER3, "en", "", "")); 56 } 57 testGetDescriptionUsingFallbackLanguage()58 public void testGetDescriptionUsingFallbackLanguage() { 59 // Mapping file exists but the number isn't present, causing it to fallback. 60 assertEquals("New York, NY", 61 reader.getDescriptionForNumber(US_NUMBER2, "de", "", "CH")); 62 // No mapping file exists, causing it to fallback. 63 assertEquals("New York, NY", 64 reader.getDescriptionForNumber(US_NUMBER2, "sv", "", "")); 65 } 66 testGetDescriptionForNonFallbackLanguage()67 public void testGetDescriptionForNonFallbackLanguage() { 68 assertEquals("", reader.getDescriptionForNumber(US_NUMBER2, "ko", "", "")); 69 } 70 testGetDescriptionForNumberWithoutMappingFile()71 public void testGetDescriptionForNumberWithoutMappingFile() { 72 assertEquals("", reader.getDescriptionForNumber(SE_NUMBER, "sv", "", "")); 73 assertEquals("", reader.getDescriptionForNumber(SE_NUMBER, "en", "", "")); 74 } 75 } 76